[cfe-dev] Improving Clang Parse Performance

James Dennett james.dennett at gmail.com
Mon Jun 11 11:13:45 PDT 2012

On Mon, Jun 11, 2012 at 10:16 AM, sccllghn <sccllghn at yahoo.com> wrote:
> I am trying to use Clang for parsing some C++ programs and have had good
> success. The problem is performance. I can parse about 400,000 lines of C
> code scattered in 400 files in about 25 minutes on a really fast machine.

That is odd.  Clang's parser is pretty fast, as C++ parsers go.  Have
you tried using an optimized build of Clang to compiler your 400
files?  400,000 lines isn't much code, and 25 minutes is a long time.

> I
> think that this is not very good, considering that I am doing a lot less
> than a compiler. Am I mistaken in my expectations?

A rule of thumb is that, when not optimizing, lexing/parsing takes
about half of the total compiler time.  If you do no work beyond
parsing you might be able to be twice as fast as clang++ when it's

> My sense is that to get a real bump in performance, I need to use
> pre-compiled header files, because the vast majority of parsing is being
> done over and over.

My guess is that something is strange in your setup, because I'd
expect that Clang is faster than that.  How long does it take to
*compile* your 400k LOC?

-- James

More information about the cfe-dev mailing list