Page MenuHomePhabricator

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

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

Details

Summary

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.

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
clangd/index/Index.cpp
39

Should this be S.ID < I?

41

&& It->ID == ID?

72

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.
clangd/index/Index.cpp
78

use Symbols.shrink_to_fit()?

83

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

clangd/index/Index.h
176

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

185

Mention the Symbols is required to be sorted.

clangd/index/SymbolCollector.h
36

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

Thanks!

clangd/index/Index.cpp
39

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

78

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.

clangd/index/SymbolCollector.h
36

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

LGTM.

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.