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 170176 clangd/CodeComplete.cpp
clangd/FindSymbols.cpp
clangd/Quality.cpp
clangd/XRefs.cpp
clangd/index/Index.h
clangd/index/Index.cpp
clangd/index/Merge.cpp
clangd/index/Serialization.cpp
clangd/index/SymbolCollector.cpp
clangd/index/YAMLSerialization.cpp
clangd/index/dex/Dex.cpp
clangd/index/dex/dexp/Dexp.cpp
unittests/clangd/CodeCompleteTests.cpp
unittests/clangd/DexTests.cpp
unittests/clangd/FileIndexTests.cpp
unittests/clangd/IndexTests.cpp
unittests/clangd/SerializationTests.cpp
unittests/clangd/SymbolCollectorTests.cpp
|
The StringRef(const char*) constructor calls strlen. Do you believe this does not have noticeable performance issue?
(A minor point: tuple::operator< calls operator< of its components in a not very efficient way. The compiler does not know compare(a, b) < 0 implies compare(b, a) > 0 and strcmp may end up being called twice.)