[cfe-dev] clang performance when building Linux

Török Edwin edwintorok at gmail.com
Sat Apr 16 09:11:45 PDT 2011


On 2011-04-16 15:01, Benjamin Kramer wrote:
> 
> On 13.04.2011, at 23:50, Török Edwin wrote:
> 
>> Hi,
>>
>> I did a performance profile of clang while building Linux kernel.
>> The difference is not much compared to gcc, clang with asserts off is a
>> bit faster than gcc, and with asserts on a bit slower.
>>
>> Here is the 'perf report' for clang with asserts off:
>> https://gist.github.com/918497
> 
>>     3.65%     clang  clang                              [.] llvm::StringMapImpl::LookupBucketFor(llvm::StringRef)
> 
> I'm a bit surprised that StringMap is the most expensive entry here, maybe microoptimizing
> the hash function (which is a byte-wise djb hash at the moment) can help a bit. If someone is
> really bored it would also be useful to test if other string hash functions like murmurhash or google's
> new city hash give better performance.

If I interpret this right then there are many collisions, and most time
is wasted comparing the key against collided items, so yes changing hash
function might help:
0.38 : 15fb0d9: 48 89 de                mov    %rbx,%rsi
16.46: 15fb0dc: f3 a6                   repz cmpsb %es:(%rdi),%ds:(%rsi)
15.37: 15fb0de: 75 b8                   jne    15fb098
<llvm::StringMapImpl::LookupBucketFor(llvm::StringRef)+0x88>
0.85 :         15fb0e0:       48 83 c4 20             add    $0x20,%rsp

Too bad I don't have callgraphs here, would be interesting to see what
calls StringMap this often.

> 
>>     2.87%     clang  clang                              [.] clang::Lexer::LexTokenInternal(clang::Token&)
> 
> This is expected, the lexer usually dominates any C compiler's run time (well, except for crazy stuff like C++ ;),
> clang's lexer is heavily optimized, I doubt we can improve much here.
> 
>>     2.74%     clang  [kernel.kallsyms]                  [k] clear_page_c
> 
> This is probably zero filling pages for malloc.
> 
>>     2.07%  genksyms  genksyms                           [.] yylex
>>     1.88%     clang  clang                              [.] clang::SourceManager::getFileIDSlow(unsigned int) const
> 
> Despite that the name contains the word slow, this function is optimized well and known to be hot.
> 
>>     1.66%     clang  libc-2.13.so                       [.] _int_malloc
> 
> Reducing mallocs is an ongoing process, clang already pool allocates a lot of its data,
> LLVM's types, constants and other stuff aren't allocated in pools at the moment but there are plans to fix that.
> 
>>     1.65%     clang  clang                              [.] clang::Lexer::LexIdentifier(clang::Token&, char const*)
>>     1.08%     clang  libstdc++.so.6.0.15                [.] 0xa5750         
>>     1.08%     clang  clang                              [.] llvm::SmallPtrSetImpl::insert_imp(void const*)
>>     1.07%     clang  clang                              [.] clang::TokenLexer::Lex(clang::Token&)




More information about the cfe-dev mailing list