chetant/LibClang — pull request #40 by sethfowler (2014-01-25 21:44:14+00:00)
Title: API cleanup and massive performance improvements

After determining that LibClang was a bottleneck in my application I was able to get huge performance improvements (at *least* 5x) by optimizing LibClang.

The most important gains came from new traversal functions, implemented in C, that collect all of the children or descendants of an AST node and return the cursors to Haskell as a vector. This eliminated the need for visitor functions that call repeatedly into Haskell from C, which was a major performance bottleneck.

Other performance improvements came from more efficient marshaling using Storable and Vector, and inlining of frequently-called functions. (Some of the most frequently called were rewritten in Haskell to avoid all FFI overhead.)

Finally, the eliminating the visitor callbacks made it possible to cleanly replace the ClangApp monad with the ClangT monad transformer. Code using the new API is much more idiomatic and can run on top of arbitrary monads. Although this doesn't directly improve performance, it makes it much easier to implement application-level optimizations like caching that are much more convenient when built on top of the State or Reader monads.