This would save us 8 bytes per ref, and buy us ~50MB in total for llvm
index (from ~350MB to ~300 MB).
The char pointer must be null-terminated, and llvm::StringSaver
guarantees it.
Paths
| Differential D53427
[clangd] Replace StringRef in SymbolLocation with a char pointer. ClosedPublic Authored by hokein on Oct 19 2018, 3:05 AM.
Details Summary This would save us 8 bytes per ref, and buy us ~50MB in total for llvm The char pointer must be null-terminated, and llvm::StringSaver
Diff Detail
Event TimelineHerald added subscribers: kadircet, arphaman, jkorous and 3 others. · View Herald TranscriptOct 19 2018, 3:05 AM Comment Actions Nice savings! My initial thought is that it seems weird to only do it for this one string - the readers look different, the serialization code has different logic etc for the different flavors of strings. This may be the right tradeoff, but I'd like to play with/think about other options for API here. One is to define a class like NullTerminatedStringRef (with a better name) that wraps a char* only, but otherwise behaves as much like stringref as we can manage. Happy for you to try some of these out or to try them myself. I think this is worth a bit of thought before committing because as shown in this patch, these APIs have quite a lot of uses!
sammccall added inline comments.
This revision is now accepted and ready to land.Nov 13 2018, 7:18 AM hokein marked 3 inline comments as done. Comment ActionsAddress review comments.
Closed by commit rL346852: [clangd] Replace StringRef in SymbolLocation with a char pointer. (authored by hokein). · Explain WhyNov 14 2018, 3:58 AM This revision was automatically updated to reflect the committed changes. alexfh added inline comments.
Revision Contents
Diff 174013 clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/DexTests.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
|
If the users of the SymbolLocation have a way to get a common "context", you could keep a list of filenames in this context and just store an index into this list (which could be even shorter). If the structure is used where no context is available, you could still keep a list of StringRefs somewhere (probably close to where the string data pointed by the StringRefs lives) and keep a StringRef * here. At a cost of one indirection you'd avoid calling strlen.
Not sure what trade-off is better for this particular use case though.