[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 09:21:41 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL341376: [clangd] Load static index asynchronously, add tracing. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51638?vs=163840&id=163847#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51638

Files:
  clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
  clang-tools-extra/trunk/clangd/index/SymbolYAML.h
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -281,9 +281,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: clang-tools-extra/trunk/clangd/index/SymbolYAML.h
===================================================================
--- clang-tools-extra/trunk/clangd/index/SymbolYAML.h
+++ clang-tools-extra/trunk/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: clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
+++ clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "SymbolYAML.h"
+#include "../Trace.h"
 #include "Index.h"
 #include "Serialization.h"
 #include "dex/DexIndex.h"
@@ -183,25 +184,31 @@
   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;
   }
   StringRef Data = Buffer->get()->getBuffer();
 
   llvm::Optional<SymbolSlab> Slab;
   if (Data.startswith("RIFF")) { // Magic for binary index file.
+    trace::Span Tracer("ParseRIFF");
     if (auto RIFF = readIndexFile(Data))
       Slab = std::move(RIFF->Symbols);
     else
       llvm::errs() << "Bad RIFF: " << llvm::toString(RIFF.takeError()) << "\n";
   } else {
+    trace::Span Tracer("ParseYAML");
     Slab = symbolsFromYAML(Data);
   }
 
+  if (!Slab)
+    return nullptr;
+  trace::Span Tracer("BuildIndex");
   return UseDex ? dex::DexIndex::build(std::move(*Slab))
                 : MemIndex::build(std::move(*Slab), RefSlab());
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51638.163847.patch
Type: text/x-patch
Size: 3296 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180904/608aad9e/attachment.bin>


More information about the cfe-commits mailing list