[cfe-commits] lazy builtins patch

Chris Lattner clattner at apple.com
Wed Nov 28 23:46:53 PST 2007

Neil inspired me to look into making the population of the identifier  
table with builtins more lazy.  Right now, all builtins are inserted  
into the identifier table as astcontext starts up, this adds several  
hundred builtins to the identifier table even for translation units  
that don't use them.  This change avoids doing it at startup time,  
instead doing it as each builtin is first referenced.

Implementing this yields about a 3% speedup on the best possible case,  
and the change is in the noise for all other cases.  Since it adds a  
significant amount of complexity, I'm not going to check it in.  Neil,  
I'd be interested to see if this improves your "startup time  
benchmark" at all though.

The effect of this is most pronounced with something like this:

without the patch:

$ echo "int X;" > ~/empty.c
$ clang ~/empty.c -stats

*** Identifier Table Stats:
# Identifiers:   585
# Empty Buckets: 7607
Hash density (#identifiers per bucket): 0.071411
Ave identifier length: 18.675214
Max identifier length: 45

Number of memory regions: 3
Bytes allocated: 19488

with the patch:

$ clang ~/empty.c -stats
*** Identifier Table Stats:
# Identifiers:   188
# Empty Buckets: 8004
Hash density (#identifiers per bucket): 0.022949
Ave identifier length: 10.973404
Max identifier length: 45

Number of memory regions: 2
Bytes allocated: 4836

The remaining identifiers are split between target-specific macro  
related stuff (~70) keywords (~70), and some other miscellaneous  
stuff.  To my surprise, getting rid of this many identifiers isn't a  
big speedup, even parsing 'empty.c'.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: lazy_builtins.patch
Type: application/octet-stream
Size: 10709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20071128/0a880707/attachment.obj>
-------------- next part --------------

More information about the cfe-commits mailing list