[PATCH] D51638: [clangd] Load static index asynchronously, add tracing.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 4 08:56:30 PDT 2018
sammccall created this revision.
sammccall added a reviewer: ioeric.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Like https://reviews.llvm.org/D51475 but simplified based on recent patches.
While here, clarify that loadIndex() takes a filename, not file content.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D51638
Files:
clangd/index/SymbolYAML.cpp
clangd/index/SymbolYAML.h
clangd/tool/ClangdMain.cpp
Index: clangd/tool/ClangdMain.cpp
===================================================================
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -280,9 +280,15 @@
Opts.BuildDynamicSymbolIndex = EnableIndex;
std::unique_ptr<SymbolIndex> StaticIdx;
if (EnableIndex && !YamlSymbolFile.empty()) {
- StaticIdx = loadIndex(YamlSymbolFile, UseDex);
- Opts.StaticIndex = StaticIdx.get();
+ // Load the index asynchronously. Meanwhile SwapIndex returns no results.
+ SwapIndex *Placeholder;
+ StaticIdx.reset(Placeholder = new SwapIndex(llvm::make_unique<MemIndex>()));
+ runAsync<void>([Placeholder] {
+ if (auto Idx = loadIndex(YamlSymbolFile))
+ Placeholder->reset(std::move(Idx));
+ });
}
+ Opts.StaticIndex = StaticIdx.get();
Opts.AsyncThreadsCount = WorkerThreadsCount;
clangd::CodeCompleteOptions CCOpts;
Index: clangd/index/SymbolYAML.h
===================================================================
--- clangd/index/SymbolYAML.h
+++ clangd/index/SymbolYAML.h
@@ -44,7 +44,7 @@
// Build an in-memory static index for global symbols from a symbol file.
// The size of global symbols should be relatively small, so that all symbols
// can be managed in memory.
-std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFile,
+std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFilename,
bool UseDex = true);
} // namespace clangd
Index: clangd/index/SymbolYAML.cpp
===================================================================
--- clangd/index/SymbolYAML.cpp
+++ clangd/index/SymbolYAML.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "SymbolYAML.h"
+#include "../Trace.h"
#include "Index.h"
#include "dex/DexIndex.h"
#include "llvm/ADT/Optional.h"
@@ -182,17 +183,24 @@
return OS.str();
}
-std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFile,
+std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFilename,
bool UseDex) {
- auto Buffer = llvm::MemoryBuffer::getFile(SymbolFile);
+ trace::Span OverallTracer("LoadIndex");
+ auto Buffer = llvm::MemoryBuffer::getFile(SymbolFilename);
if (!Buffer) {
- llvm::errs() << "Can't open " << SymbolFile << "\n";
+ llvm::errs() << "Can't open " << SymbolFilename << "\n";
return nullptr;
}
- auto Slab = symbolsFromYAML(Buffer.get()->getBuffer());
+ StringRef Data = Buffer.get()->getBuffer();
+ llvm::Optional<SymbolSlab> SymbolSlab;
+ {
+ trace::Span Tracer("ParseYAML");
+ auto Slab = symbolsFromYAML(Data);
+ }
- return UseDex ? dex::DexIndex::build(std::move(Slab))
- : MemIndex::build(std::move(Slab), RefSlab());
+ trace::Span Tracer("BuildIndex");
+ return UseDex ? dex::DexIndex::build(std::move(*SymbolSlab))
+ : MemIndex::build(std::move(*SymbolSlab), RefSlab());
}
} // namespace clangd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51638.163840.patch
Type: text/x-patch
Size: 2990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180904/ad7b45cd/attachment-0001.bin>
More information about the cfe-commits
mailing list