Currently, SymbolIndex::estimateMemoryUsage() returns the "overhead" estimate, i.e. the estimate of the Index data structure excluding SymbolSlab size. This patch propagates information about paired SymbolSlab size where necessary.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
I should use SymbolSlab.bytes() instead of SymbolSlab.size(). Either way, something seems to be wrong, because manually checking the PairedSlabSize made me suspicious.
Resolved the issues. Measurements show that static Dex index for LLVM takes ~140 MB, ~80 MB of which is the size of SymbolSlab.
This looks reasonable!
This is going to conflict with D51422, you might want to rebase.
clang-tools-extra/clangd/index/MemIndex.h | ||
---|---|---|
26 ↗ | (On Diff #163519) | could you make these names somewhat more abstract (e.g. BackingMemory rather than SlabSize)? |
I'll rebase it on top of D51422 and address the last comment before proceeding to the review.
clang-tools-extra/clangd/index/dex/DexIndex.cpp | ||
---|---|---|
184 ↗ | (On Diff #163523) | Why not use LookupTable.getMemorySize() directly? Is it intentionally for not counting non-used but allocated buckets? Same for the below two as well. |
clang-tools-extra/clangd/index/FileIndex.cpp | ||
---|---|---|
91 ↗ | (On Diff #163523) | Why not bytes here as well? |
clang-tools-extra/clangd/index/FileIndex.cpp | ||
---|---|---|
144 ↗ | (On Diff #163786) | This can be a bit tricky. Generally, the size of a FileIndex is the size of FSymbols plus the overhead of the underlying index, but there can be multiple snapshots of symbols in SwapIndex. I think we can treat them as burst and only consider the size of the latest snapshot. FSymbols and the index have shared ownership to the symbol corpus. We can make either of them bookkeep the size, but I think it might be more straightforward to let the index "own" the size. You could set the payload size when creating the index, and you wouldn't need to expose estimateMemoryUsage from FSymbols. |
clang-tools-extra/clangd/index/dex/DexIndex.h | ||
44 ↗ | (On Diff #163786) | For this constructor, the index doesn't own the backing data. We should probably not include it in the estimation? (same for MemIndex) |
53 ↗ | (On Diff #163786) | nit: maybe call BackingDataSize? BackingMemory sounds like the actual memory. Maybe also put the parameter right after BackingData, as they are closely related? (same for MemIndex) |
100 ↗ | (On Diff #163786) | nit: =0? |
LG with a few nits
clang-tools-extra/clangd/index/FileIndex.cpp | ||
---|---|---|
121 ↗ | (On Diff #163786) | this isn't safe as it doesn't acquire the mutex |
144 ↗ | (On Diff #163786) | (I had trouble parsing this at first - If I understand right, you want the *memIndex* to own the size, and FileIndex to just inherit SwapIndex::estimateMemoryUsage which delegates to MemIndex::estimateMemoryUsage?) I like this idea, it's simpler and also means one less place you need to lock, which is always nice. |
clang-tools-extra/clangd/index/MemIndex.h | ||
32 ↗ | (On Diff #163786) | I don't think defaulting this parameter makes sense, seems like an easy source of bugs |
70 ↗ | (On Diff #163786) | just // Size of memory retained by KeepAlive? (similar in Dex) |
clang-tools-extra/clangd/index/FileIndex.cpp | ||
---|---|---|
144 ↗ | (On Diff #163786) | Yes, that's correct. Thanks for the clarification! |
clang-tools-extra/clangd/index/FileIndex.cpp | ||
---|---|---|
135 ↗ | (On Diff #164369) | this size should be calculated from the slabs above |
clang-tools-extra/clangd/index/FileIndex.cpp | ||
---|---|---|
131 ↗ | (On Diff #164377) | also the refslabs and refsstorage |
clang-tools-extra/clangd/index/Index.h | ||
---|---|---|
512 ↗ | (On Diff #164643) | This one is out of sync; fixed in the previous update :) |