This is an archive of the discontinued LLVM Phabricator instance.

Hash symbol names only once per global SymbolBody
ClosedPublic

Authored by • rafael on Apr 12 2016, 11:13 AM.

Details

Reviewers
ruiu
Summary

The DenseMap doesn't store hash results. This means that when it is resized it has to recompute them.

This patch is a small hack that wraps the StringRef in a struct that remembers the hash value. That way we can be sure it is only hashed once.

This gives at least a small speedup in every testcase. The largest win is in a fast link (no icf, no gc sections) of chromium. The link goes from 1.821525390 to 1.740146930 seconds.

Diff Detail

Event Timeline

• rafael retitled this revision from to Hash symbol names only once per global SymbolBody.
• rafael updated this object.
• rafael added a reviewer: ruiu.
• rafael added a subscriber: llvm-commits.
sanjoy added a subscriber: sanjoy.Apr 12 2016, 11:44 AM

Could this live in include/llvm/ADT/ instead? Maybe even in StringRef.h?

ruiu edited edge metadata.Apr 12 2016, 11:45 AM

This is a very good change -- simple and effective.

ELF/SymbolTable.h
25

Do you have to use DenseMapInfo<StringRef>::getHashValue? I'd just use llvm::hash_value.

30

The size of unsigned int depends on the hosting platform, not the target platform, so SymName would have different hashes on 32-bit and 64-bit. Does this code produces the identical binaries when cross-linking on different machines?

30

I'd name Hash instead of HashValue.

ruiu added a comment.Apr 12 2016, 12:05 PM

Sanjoy,

How would you add this to StringRef? Do you want to add a new word to StringRef for a hash value or are you suggesting something else?

In D19025#398778, @ruiu wrote:

Sanjoy,

How would you add this to StringRef? Do you want to add a new word to StringRef for a hash value or are you suggesting something else?

I meant just moving the Symbol class (possibly renamed to something more generic) to somewhere in llvm/ADT so that it is easily discoverable. Given that StringRef s are immutable anyway (so s/StringRef/Symbol in a DenseMap etc. is always correct), this looks like it could be useful more generally.

I didn't mean to suggest we should change StringRef itself.

ruiu added a comment.Apr 12 2016, 12:39 PM

That sounds like a reasonable plan.

• rafael updated this revision to Diff 53510.Apr 12 2016, 7:01 PM
• rafael edited edge metadata.
ruiu accepted this revision.Apr 14 2016, 12:13 PM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Apr 14 2016, 12:13 PM
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in r266357.