Skip to content

Commit aed965d

Browse files
committed
[lldb] Don't construct the demangled strings while indexing the symbol table
The symbol table needs to demangle all symbol names when building its index. However, this doesn't require the full mangled name: we only need the base name and the function declaration context. Currently, we always construct the demangled string during indexing and cache it in the string pool as a way to speed up future lookups. Constructing the demangled string is by far the most expensive step of the demangling process, because the output string can be exponentially larger than the input and unless you're dumping the symbol table, many of those demangled names will not be needed again. This patch avoids constructing the full demangled string when we can partially demangle. This speeds up indexing and reduces memory usage. I gathered some numbers by attaching to Slack: Before ------ Memory usage: 280MB Benchmark 1: ./bin/lldb -n Slack -o quit Time (mean ± σ): 4.829 s ± 0.518 s [User: 4.012 s, System: 0.208 s] Range (min … max): 4.624 s … 6.294 s 10 runs After ----- Memory usage: 189MB Benchmark 1: ./bin/lldb -n Slack -o quit Time (mean ± σ): 4.182 s ± 0.025 s [User: 3.536 s, System: 0.192 s] Range (min … max): 4.152 s … 4.233 s 10 runs Differential revision: https://reviews.llvm.org/D118814
1 parent fa52788 commit aed965d

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

lldb/source/Core/Mangled.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,24 +214,16 @@ bool Mangled::DemangleWithRichManglingInfo(
214214
case eManglingSchemeItanium:
215215
// We want the rich mangling info here, so we don't care whether or not
216216
// there is a demangled string in the pool already.
217-
if (context.FromItaniumName(m_mangled)) {
218-
// If we got an info, we have a name. Copy to string pool and connect the
219-
// counterparts to accelerate later access in GetDemangledName().
220-
m_demangled.SetStringWithMangledCounterpart(context.ParseFullName(),
221-
m_mangled);
222-
return true;
223-
} else {
224-
m_demangled.SetCString("");
225-
return false;
226-
}
217+
return context.FromItaniumName(m_mangled);
227218

228219
case eManglingSchemeMSVC: {
229220
// We have no rich mangling for MSVC-mangled names yet, so first try to
230221
// demangle it if necessary.
231222
if (!m_demangled && !m_mangled.GetMangledCounterpart(m_demangled)) {
232223
if (char *d = GetMSVCDemangledStr(m_mangled.GetCString())) {
233-
// If we got an info, we have a name. Copy to string pool and connect
234-
// the counterparts to accelerate later access in GetDemangledName().
224+
// Without the rich mangling info we have to demangle the full name.
225+
// Copy it to string pool and connect the counterparts to accelerate
226+
// later access in GetDemangledName().
235227
m_demangled.SetStringWithMangledCounterpart(llvm::StringRef(d),
236228
m_mangled);
237229
::free(d);

lldb/source/Symbol/Symtab.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,10 @@ void Symtab::InitNameIndexes() {
328328

329329
const SymbolType type = symbol->GetType();
330330
if (type == eSymbolTypeCode || type == eSymbolTypeResolver) {
331-
if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name))
331+
if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name)) {
332332
RegisterMangledNameEntry(value, class_contexts, backlog, rmc);
333+
continue;
334+
}
333335
}
334336
}
335337

lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def test_dyld_trie_symbols(self):
4343
self.assertEqual(unstripped_Z3pat_symbols.GetSize(), 1)
4444
unstripped_pat_symbols = unstripped_target.FindSymbols("pat")
4545
self.assertEqual(unstripped_pat_symbols.GetSize(), 1)
46-
unstripped_patint_symbols = unstripped_target.FindSymbols("pat(int)")
47-
self.assertEqual(unstripped_patint_symbols.GetSize(), 1)
4846

4947
unstripped_bar_symbols = unstripped_target.FindSymbols("bar")
5048
self.assertEqual(unstripped_bar_symbols.GetSize(), 1)
@@ -77,8 +75,6 @@ def test_dyld_trie_symbols(self):
7775
self.assertEqual(stripped_Z3pat_symbols.GetSize(), 1)
7876
stripped_pat_symbols = stripped_target.FindSymbols("pat")
7977
self.assertEqual(stripped_pat_symbols.GetSize(), 1)
80-
stripped_patint_symbols = stripped_target.FindSymbols("pat(int)")
81-
self.assertEqual(stripped_patint_symbols.GetSize(), 1)
8278

8379
# bar should have been strippped. We should not find it, or the
8480
# stripping went wrong.

0 commit comments

Comments
 (0)