This is an archive of the discontinued LLVM Phabricator instance.

[COFF] Pack Name in Symbol as is done in ELF
ClosedPublic

Authored by rnk on Apr 4 2019, 5:29 PM.

Details

Summary

This assumes all symbols are <4GB long, so we can store them as a 32-bit
integer. This reorders the fields so the length appears first, packing
with the other bitfield data in the base Symbol object.

This saved 70MB / 3.60% of heap allocations when linking
browser_tests.exe with no PDB. It's not much as a percentage, but worth
doing. I didn't do performance measurements, I don't think it will be
measurable in time.

Event Timeline

rnk created this revision.Apr 4 2019, 5:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2019, 5:29 PM
ruiu added inline comments.Apr 4 2019, 5:43 PM
lld/COFF/Symbols.h
111

I'd use uint32_t to match the comment.

111

We have the same hack for ELF, and we name these variables NameSize and NameData.

aganea added inline comments.Apr 4 2019, 6:03 PM
lld/COFF/Symbols.h
111

You could save more by packing this with the bitfield above. ‘SymbolKind’ doesn’t need more than 4 bits, and that would free 21 bits for ‘NameLen’. In practical terms, do we really expect symbol lengths > 2^21 chars? Worst case, there could be a slower/higher mem. codepath for off-the-limits case?

aganea marked an inline comment as done.Apr 4 2019, 6:06 PM
aganea added inline comments.
lld/COFF/Symbols.h
111

Forget what I said, it’ll be aligned on 64-bits because of the pointer that follows.

rnk updated this revision to Diff 193913.Apr 5 2019, 11:07 AM
  • update naming
thakis added a subscriber: thakis.Apr 5 2019, 12:49 PM
thakis added inline comments.
lld/COFF/Symbols.h
111

If uint32_t happens to be a long, will this prevent packing with the bitfields in the ms abi? maybe unsigned is better for that reason?

rnk marked an inline comment as done.Apr 5 2019, 3:10 PM
rnk added inline comments.
lld/COFF/Symbols.h
111

Yes, and I think that's part of why I used unsigned in the first place. However, right now it's not a bitfield so it won't matter. If we do ever shrink NameSize even further with bitfields, then yes, we'd want to update them all to some common type.

ruiu accepted this revision.Apr 7 2019, 11:24 PM

LGTM

This revision is now accepted and ready to land.Apr 7 2019, 11:24 PM
This revision was automatically updated to reflect the committed changes.