[PATCH] D52503: [clangd] More precise index memory usage estimate

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 25 10:38:48 PDT 2018


kbobyrev added inline comments.


================
Comment at: clang-tools-extra/clangd/index/dex/Dex.cpp:251
   Bytes += InvertedIndex.getMemorySize();
-  for (const auto &P : InvertedIndex)
-    Bytes += P.second.bytes();
+  for (const auto &TokenToPostingList : InvertedIndex)
+    Bytes += TokenToPostingList.first.Data.size() +
----------------
ioeric wrote:
> Would `InvertedIndex.getMemorySize()` be a better estimate?
IIUC this is only precise for the objects which do not make any allocations (e.g. `std::vector` and `std::string` memory estimate would not be "correct").

>From the documentation

> This is just the raw memory used by DenseMap. If entries are pointers to objects, the size of the referenced objects are not included.

I also have `Bytes += InvertedIndex.getMemorySize();` above, so the purpose of this code would be to take into account the size of these "reference objects".

However, since `PostingList::bytes()` also returns underlying `std::vector` size, this code will probably add these `std::vector` objects size twice (the first one was in `InvertedIndex.getMemorySize()`). I should fix that.


https://reviews.llvm.org/D52503





More information about the cfe-commits mailing list