diff options
author | Haojian Wu <hokein@google.com> | 2018-04-11 08:13:07 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2018-04-11 08:13:07 +0000 |
commit | 9f36c7e704ea7a604a7962452b15dc8646659744 (patch) | |
tree | b9020124ee56064658d9167de01a5968e40d14bb /clang/lib/Tooling/Execution.cpp | |
parent | 33922a511dbb1363814428d3fa662049ee751638 (diff) | |
download | bcm5719-llvm-9f36c7e704ea7a604a7962452b15dc8646659744.tar.gz bcm5719-llvm-9f36c7e704ea7a604a7962452b15dc8646659744.zip |
[Tooling] Optimize memory usage in InMemoryToolResults.
Avoid storing duplicated "std::string"s.
clangd's global-symbol-builder takes 20+GB memory running across LLVM
repository. With this patch, the used memory is ~10GB (running on 48
threads, most of meory are AST-related).
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D45479
llvm-svn: 329784
Diffstat (limited to 'clang/lib/Tooling/Execution.cpp')
-rw-r--r-- | clang/lib/Tooling/Execution.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Tooling/Execution.cpp b/clang/lib/Tooling/Execution.cpp index ff68f85adb2..5d6559fb2b4 100644 --- a/clang/lib/Tooling/Execution.cpp +++ b/clang/lib/Tooling/Execution.cpp @@ -21,10 +21,19 @@ static llvm::cl::opt<std::string> llvm::cl::init("standalone")); void InMemoryToolResults::addResult(StringRef Key, StringRef Value) { - KVResults.push_back({Key.str(), Value.str()}); + auto Intern = [&](StringRef &V) { + auto R = Strings.insert(V); + if (R.second) { // A new entry, create a new string copy. + *R.first = StringsPool.save(V); + } + V = *R.first; + }; + Intern(Key); + Intern(Value); + KVResults.push_back({Key, Value}); } -std::vector<std::pair<std::string, std::string>> +std::vector<std::pair<llvm::StringRef, llvm::StringRef>> InMemoryToolResults::AllKVResults() { return KVResults; } |