[clang-tools-extra] r355676 - [clangd] Deduplicate Refs on the fly.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 8 01:26:30 PST 2019
Author: hokein
Date: Fri Mar 8 01:26:30 2019
New Revision: 355676
URL: http://llvm.org/viewvc/llvm-project?rev=355676&view=rev
Log:
[clangd] Deduplicate Refs on the fly.
Summary:
Currently, we only do deduplication when we flush final results. We may
have huge duplications (refs from headers) during the indexing period (running
clangd-indexer on Chromium).
With this change, clangd-indexer can index the whole chromium projects
(48 threads, 40 GB peak memory usage).
Reviewers: kadircet
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, mgrang, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D59092
Modified:
clang-tools-extra/trunk/clangd/index/Ref.cpp
clang-tools-extra/trunk/clangd/index/Ref.h
clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp
Modified: clang-tools-extra/trunk/clangd/index/Ref.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Ref.cpp?rev=355676&r1=355675&r2=355676&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Ref.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Ref.cpp Fri Mar 8 01:26:30 2019
@@ -33,9 +33,12 @@ llvm::raw_ostream &operator<<(llvm::raw_
void RefSlab::Builder::insert(const SymbolID &ID, const Ref &S) {
auto &M = Refs[ID];
- M.push_back(S);
- M.back().Location.FileURI =
- UniqueStrings.save(M.back().Location.FileURI).data();
+ if (M.count(S))
+ return;
+ Ref R = S;
+ R.Location.FileURI =
+ UniqueStrings.save(R.Location.FileURI).data();
+ M.insert(std::move(R));
}
RefSlab RefSlab::Builder::build() && {
@@ -45,11 +48,7 @@ RefSlab RefSlab::Builder::build() && {
Result.reserve(Refs.size());
size_t NumRefs = 0;
for (auto &Sym : Refs) {
- auto &SymRefs = Sym.second;
- llvm::sort(SymRefs);
- // FIXME: do we really need to dedup?
- SymRefs.erase(std::unique(SymRefs.begin(), SymRefs.end()), SymRefs.end());
-
+ std::vector<Ref> SymRefs(Sym.second.begin(), Sym.second.end());
NumRefs += SymRefs.size();
Result.emplace_back(Sym.first, llvm::ArrayRef<Ref>(SymRefs).copy(Arena));
}
Modified: clang-tools-extra/trunk/clangd/index/Ref.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Ref.h?rev=355676&r1=355675&r2=355676&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Ref.h (original)
+++ clang-tools-extra/trunk/clangd/index/Ref.h Fri Mar 8 01:26:30 2019
@@ -16,6 +16,7 @@
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdint>
+#include <set>
#include <utility>
namespace clang {
@@ -67,6 +68,7 @@ llvm::raw_ostream &operator<<(llvm::raw_
/// Filenames are deduplicated.
class RefSlab {
public:
+ // Refs are stored in order.
using value_type = std::pair<SymbolID, llvm::ArrayRef<Ref>>;
using const_iterator = std::vector<value_type>::const_iterator;
using iterator = const_iterator;
@@ -99,7 +101,7 @@ public:
private:
llvm::BumpPtrAllocator Arena;
llvm::UniqueStringSaver UniqueStrings; // Contents on the arena.
- llvm::DenseMap<SymbolID, std::vector<Ref>> Refs;
+ llvm::DenseMap<SymbolID, std::set<Ref>> Refs;
};
private:
Modified: clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp?rev=355676&r1=355675&r2=355676&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp Fri Mar 8 01:26:30 2019
@@ -56,7 +56,7 @@ public:
[&](RefSlab S) {
std::lock_guard<std::mutex> Lock(SymbolsMu);
for (const auto &Sym : S) {
- // No need to merge as currently all Refs are from main file.
+ // Deduplication happens during insertion.
for (const auto &Ref : Sym.second)
Refs.insert(Sym.first, Ref);
}
More information about the cfe-commits
mailing list