[clangd] Fix bugs with incorrect memory estimate report

* With the current implementation, `sizeof(std::vector<Chunk>)` is added
twice to the `Dex` memory estimate which is incorrect
* `Dex` logs memory usage estimation before `BackingDataSize` is set and
hence the log report excludes size of the external `SymbolSlab` which is
coupled with `Dex` instance

Reviewed By: ioeric

Differential Revision: https://reviews.llvm.org/D52503

llvm-svn: 343117
This commit is contained in:
Kirill Bobyrev 2018-09-26 15:06:23 +00:00
parent 0cdf629394
commit ea4f20c6be
3 changed files with 12 additions and 11 deletions

View File

@ -6,8 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Serialization.h"
#include "Index.h"
#include "Logger.h"
#include "RIFF.h"
#include "Trace.h"
#include "dex/Dex.h"
@ -433,8 +435,12 @@ std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFilename,
}
trace::Span Tracer("BuildIndex");
return UseDex ? dex::Dex::build(std::move(Symbols), URISchemes)
: MemIndex::build(std::move(Symbols), std::move(Refs));
auto Index = UseDex ? dex::Dex::build(std::move(Symbols), URISchemes)
: MemIndex::build(std::move(Symbols), std::move(Refs));
vlog("Loaded {0} from {1} with estimated memory usage {2}",
UseDex ? "Dex" : "MemIndex", SymbolFilename,
Index->estimateMemoryUsage());
return Index;
}
} // namespace clangd

View File

@ -130,9 +130,6 @@ void Dex::buildIndex() {
for (const auto &TokenToPostingList : TempInvertedIndex)
InvertedIndex.insert(
{TokenToPostingList.first, PostingList(TokenToPostingList.second)});
vlog("Built Dex with estimated memory usage {0} bytes.",
estimateMemoryUsage());
}
/// Constructs iterators over tokens extracted from the query and exhausts it
@ -248,8 +245,8 @@ size_t Dex::estimateMemoryUsage() const {
Bytes += SymbolQuality.size() * sizeof(float);
Bytes += LookupTable.getMemorySize();
Bytes += InvertedIndex.getMemorySize();
for (const auto &P : InvertedIndex)
Bytes += P.second.bytes();
for (const auto &TokenToPostingList : InvertedIndex)
Bytes += TokenToPostingList.second.bytes();
return Bytes + BackingDataSize;
}

View File

@ -66,10 +66,8 @@ public:
/// go through the chunks and decompress them on-the-fly when necessary.
std::unique_ptr<Iterator> iterator() const;
/// Returns in-memory size.
size_t bytes() const {
return sizeof(Chunk) + Chunks.capacity() * sizeof(Chunk);
}
/// Returns in-memory size of external storage.
size_t bytes() const { return Chunks.capacity() * sizeof(Chunk); }
private:
const std::vector<Chunk> Chunks;