This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Log memory usage of DexIndex and MemIndex
ClosedPublic

Authored by kbobyrev on Aug 23 2018, 1:17 AM.

Details

Summary

This patch prints information about built index size estimation to verbose logs. This is useful for optimizing memory usage of DexIndex and comparisons with MemIndex.

Diff Detail

Repository
rL LLVM

Event Timeline

kbobyrev created this revision.Aug 23 2018, 1:17 AM
sammccall added inline comments.Aug 23 2018, 1:52 AM
clang-tools-extra/clangd/index/MemIndex.cpp
105 ↗(On Diff #162141)

access to Index needs to be guarded by mutex

105 ↗(On Diff #162141)

Index.getMemorySize() is a better estimate.

clang-tools-extra/clangd/index/MemIndex.h
43 ↗(On Diff #162141)

Can you return bytes here, and do lossy conversions at display time instead?

(Not sure the conversions are even worth it. e.g. it's may be interesting to compare even <1mb indexes)

44 ↗(On Diff #162141)

I'd suggest making this part of the public interface, and implementing it for all (the implementations should be trivial).

This is useful e.g. for monitoring. We may want vim's :YcmDebugInfo to return this, etc.

clang-tools-extra/clangd/index/dex/DexIndex.cpp
178 ↗(On Diff #162141)

again, LookupTable.getMemorySize() and others.

180 ↗(On Diff #162141)

I think you're not counting the size of the actual symbols.
This is difficult to do precisely, but avoiding it seems misleading (we have "shared ownership" but it's basically exclusive). What's the plan here?

182 ↗(On Diff #162141)

why is only the InvertedIndex access guarded by the mutex?

kbobyrev updated this revision to Diff 162146.Aug 23 2018, 3:27 AM
kbobyrev marked 6 inline comments as done.

Address a bunch of comments.

kbobyrev added inline comments.Aug 23 2018, 4:55 AM
clang-tools-extra/clangd/index/dex/DexIndex.cpp
180 ↗(On Diff #162141)

As discussed offline: I should put a FIXME and leave it for later.

Some drive-by NITS.

clang-tools-extra/clangd/index/MemIndex.cpp
109 ↗(On Diff #162146)

Why not simply return Index.getMemorySize() under a lock?

clang-tools-extra/clangd/index/dex/DexIndex.cpp
180 ↗(On Diff #162146)

Maybe put a lock over all of the function and remove the unneeded compound statement?

kbobyrev updated this revision to Diff 162184.Aug 23 2018, 7:50 AM
kbobyrev marked 2 inline comments as done.

Slightly simplify the code.

Do we plan to expose an API in ClangdServer to allow C++ API users to track index memory usages?

clang-tools-extra/clangd/index/FileIndex.cpp
123 ↗(On Diff #162184)

I think the URI scheme names should be negligible.

clang-tools-extra/clangd/index/dex/DexIndex.cpp
180 ↗(On Diff #162141)

SymbolSlab provides a pretty good estimation of memory usage, and I think we should try to use if possible (as Sam suggested, it could be misleading without the size of index corpus). IIUC, the challenge here is that SymbolSlabs can be hiden behind shared_ptr, and index might not have access to the underlying slabs. If that's the case, I think it would be reasonable to ask callers of build to also pass in an estimated size of the hidden slabs?

sammccall accepted this revision.Aug 24 2018, 12:54 AM
sammccall added inline comments.
clang-tools-extra/clangd/index/FileIndex.cpp
123 ↗(On Diff #162184)

yeah, just drop this I think.

clang-tools-extra/clangd/index/Index.h
391 ↗(On Diff #162184)

it might be useful --> we should include both :-)

This revision is now accepted and ready to land.Aug 24 2018, 12:54 AM
kbobyrev updated this revision to Diff 162334.Aug 24 2018, 1:15 AM
kbobyrev marked 3 inline comments as done.

Address few concerns.

Do we plan to expose an API in ClangdServer to allow C++ API users to track index memory usages?

I think we do, IIUC the conclusion of the offline discussion was that it might be useful for the clients. However, that would require SymbolSlab estimation, too (which is probably out of scope of this patch).

This revision was automatically updated to reflect the committed changes.