[clang-tools-extra] r343117 - [clangd] Fix bugs with incorrect memory estimate report
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 26 08:06:23 PDT 2018
Author: omtcyfz
Date: Wed Sep 26 08:06:23 2018
New Revision: 343117
URL: http://llvm.org/viewvc/llvm-project?rev=343117&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
clang-tools-extra/trunk/clangd/index/dex/PostingList.h
Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=343117&r1=343116&r2=343117&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Wed Sep 26 08:06:23 2018
@@ -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(l
}
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
Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=343117&r1=343116&r2=343117&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp Wed Sep 26 08:06:23 2018
@@ -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;
}
Modified: clang-tools-extra/trunk/clangd/index/dex/PostingList.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/PostingList.h?rev=343117&r1=343116&r2=343117&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/dex/PostingList.h (original)
+++ clang-tools-extra/trunk/clangd/index/dex/PostingList.h Wed Sep 26 08:06:23 2018
@@ -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;
More information about the cfe-commits
mailing list