Page MenuHomePhabricator

[clangd] Use Builder for symbol slabs, and use sorted-vector for storage

Authored by sammccall on Dec 21 2017, 11:03 AM.



This improves a few things:

  • the insert -> freeze -> read sequence is now enforced/communicated by the type system
  • SymbolSlab::const_iterator iterates over symbols, not over id-symbol pairs
  • we avoid permanently storing a second copy of the IDs, and the string map's hashtable

The slab size is now down to 21.8MB for the LLVM project.
Of this only 2.7MB is strings, the rest is #symbols * sizeof(Symbol).
sizeof(Symbol) is currently 96, which seems too big - I think
SymbolInfo isn't efficiently packed. That's a topic for another patch!

Also added simple API to see the memory usage/#symbols of a slab, since
it seems likely we will continue to care about this.

Diff Detail


Event Timeline

sammccall created this revision.Dec 21 2017, 11:03 AM

minor doc and code layout tweaks

ilya-biryukov added inline comments.Dec 22 2017, 3:23 AM
39 ↗(On Diff #127918)

Should this be S.ID < I?

41 ↗(On Diff #127918)

&& It->ID == ID?

72 ↗(On Diff #127918)

NIT: Maybe put assignment into a separate statement?
It's not too hard to see what's going on in the current code, but this line certainly gave me a pause.

hokein added a subscriber: hokein.Dec 22 2017, 4:19 AM
hokein added inline comments.
76 ↗(On Diff #127918)

use Symbols.shrink_to_fit()?

81 ↗(On Diff #127918)

Maybe rename it to NewArena, we already have a member called Arena.

174 ↗(On Diff #127918)

worth a comment saying the value of the map is the vector index of Symbols, it took me a while to understand.

182 ↗(On Diff #127918)

Mention the Symbols is required to be sorted.

36 ↗(On Diff #127918)

Maybe name it SymbolBuilder to avoid confusion -- Symbols indicates its type is SymbolSlab.

sammccall marked 6 inline comments as done.Dec 22 2017, 12:04 PM


39 ↗(On Diff #127918)

Wow, good catch (both here and below)!
Added a test (for some reason I thought we had one for this sort of stuff)

76 ↗(On Diff #127918)

This is only a hint, and on my system it's a no-op. I think we know enough about the lifecycle here to make forcing the shrink worth it.

36 ↗(On Diff #127918)

Hmm, I'm not sure SymbolBuilder is a better name - it doesn't build symbols.
I'm not really seeing the association between Symbols and SymbolSlab - a SymbolSlab::Builder is also a collection of symbols.

sammccall marked an inline comment as done.

Address review comments, and update new GlobalSymbolBuilder tool for new API.

hokein accepted this revision.Dec 22 2017, 10:54 PM


This revision is now accepted and ready to land.Dec 22 2017, 10:54 PM
This revision was automatically updated to reflect the committed changes.