Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp =================================================================== --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -66,6 +66,29 @@ return Requests; } +// This is not a *real* benchmark: it shows size of built MemIndex (in bytes). +// Same for the next "benchmark". +// FIXME(kbobyrev): Should this be separated into the BackingMemorySize +// (underlying SymbolSlab size) and Symbol Index (MemIndex/Dex) overhead? +static void MemSize(benchmark::State &State) { + const auto Mem = buildMem(); + for (auto _ : State) + // Divide size of Mem by 1000 so that it will be correctly displayed in the + // benchmark report (possible options for time units are ms, ns and us). + State.SetIterationTime(/*double Seconds=*/Mem->estimateMemoryUsage() / + 1000); + State.counters["Memory Usage (bytes)"] = Mem->estimateMemoryUsage(); +} +BENCHMARK(MemSize)->UseManualTime()->Unit(benchmark::kMillisecond); + +static void DexSize(benchmark::State &State) { + const auto Dex = buildDex(); + for (auto _ : State) + State.SetIterationTime(Dex->estimateMemoryUsage() / 1000); + State.counters["Memory Usage (bytes)"] = Dex->estimateMemoryUsage(); +} +BENCHMARK(DexSize)->UseManualTime()->Unit(benchmark::kMillisecond); + static void MemQueries(benchmark::State &State) { const auto Mem = buildMem(); const auto Requests = extractQueriesFromLogs(); @@ -73,7 +96,7 @@ for (const auto &Request : Requests) Mem->fuzzyFind(Request, [](const Symbol &S) {}); } -BENCHMARK(MemQueries); +BENCHMARK(MemQueries)->Unit(benchmark::kMillisecond); static void DexQueries(benchmark::State &State) { const auto Dex = buildDex(); @@ -82,7 +105,7 @@ for (const auto &Request : Requests) Dex->fuzzyFind(Request, [](const Symbol &S) {}); } -BENCHMARK(DexQueries); +BENCHMARK(DexQueries)->Unit(benchmark::kMillisecond); } // namespace } // namespace clangd @@ -108,4 +131,5 @@ argc -= 2; ::benchmark::Initialize(&argc, argv); ::benchmark::RunSpecifiedBenchmarks(); + return 0; } Index: clang-tools-extra/clangd/index/SymbolYAML.cpp =================================================================== --- clang-tools-extra/clangd/index/SymbolYAML.cpp +++ clang-tools-extra/clangd/index/SymbolYAML.cpp @@ -9,6 +9,7 @@ #include "SymbolYAML.h" #include "Index.h" +#include "Logger.h" #include "Serialization.h" #include "Trace.h" #include "dex/Dex.h" @@ -228,8 +229,12 @@ if (!Slab) return nullptr; trace::Span Tracer("BuildIndex"); - return UseDex ? dex::Dex::build(std::move(*Slab), URISchemes) - : MemIndex::build(std::move(*Slab), RefSlab()); + auto Index = UseDex ? dex::Dex::build(std::move(*Slab), URISchemes) + : MemIndex::build(std::move(*Slab), RefSlab()); + vlog("Loaded {0} from {1} with estimated memory usage {2}", + UseDex ? "Dex" : "MemIndex", SymbolFilename, + Index->estimateMemoryUsage()); + return Index; } } // namespace clangd Index: clang-tools-extra/clangd/index/dex/Dex.cpp =================================================================== --- clang-tools-extra/clangd/index/dex/Dex.cpp +++ clang-tools-extra/clangd/index/dex/Dex.cpp @@ -124,9 +124,6 @@ for (const auto &TokenToPostingList : TempInvertedIndex) InvertedIndex.insert({TokenToPostingList.first, PostingList(move(TokenToPostingList.second))}); - - vlog("Built Dex with estimated memory usage {0} bytes.", - estimateMemoryUsage()); } /// Constructs iterators over tokens extracted from the query and exhausts it @@ -239,7 +236,7 @@ Bytes += LookupTable.getMemorySize(); Bytes += InvertedIndex.getMemorySize(); for (const auto &P : InvertedIndex) - Bytes += P.second.bytes(); + Bytes += P.first.Data.size() + P.second.bytes(); return Bytes + BackingDataSize; }