Skip to content

Commit 9902e36

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 (cherry picked from commit aed965d)
1 parent e2cad86 commit 9902e36

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

lldb/source/Core/Mangled.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,24 +240,16 @@ bool Mangled::DemangleWithRichManglingInfo(
240240
case eManglingSchemeItanium:
241241
// We want the rich mangling info here, so we don't care whether or not
242242
// there is a demangled string in the pool already.
243-
if (context.FromItaniumName(m_mangled)) {
244-
// If we got an info, we have a name. Copy to string pool and connect the
245-
// counterparts to accelerate later access in GetDemangledName().
246-
m_demangled.SetStringWithMangledCounterpart(context.ParseFullName(),
247-
m_mangled);
248-
return true;
249-
} else {
250-
m_demangled.SetCString("");
251-
return false;
252-
}
243+
return context.FromItaniumName(m_mangled);
253244

254245
case eManglingSchemeMSVC: {
255246
// We have no rich mangling for MSVC-mangled names yet, so first try to
256247
// demangle it if necessary.
257248
if (!m_demangled && !m_mangled.GetMangledCounterpart(m_demangled)) {
258249
if (char *d = GetMSVCDemangledStr(m_mangled.GetCString())) {
259-
// If we got an info, we have a name. Copy to string pool and connect
260-
// the counterparts to accelerate later access in GetDemangledName().
250+
// Without the rich mangling info we have to demangle the full name.
251+
// Copy it to string pool and connect the counterparts to accelerate
252+
// later access in GetDemangledName().
261253
m_demangled.SetStringWithMangledCounterpart(llvm::StringRef(d),
262254
m_mangled);
263255
::free(d);

lldb/source/Symbol/Symtab.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,13 @@ void Symtab::InitNameIndexes() {
330330

331331
const SymbolType type = symbol->GetType();
332332
if (type == eSymbolTypeCode || type == eSymbolTypeResolver) {
333-
if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name))
333+
if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name)) {
334334
RegisterMangledNameEntry(value, class_contexts, backlog, rmc);
335+
continue;
336+
}
335337
#ifdef LLDB_ENABLE_SWIFT
336-
else if (SwiftLanguageRuntime::IsSwiftMangledName(name.GetStringRef())) {
338+
else if (SwiftLanguageRuntime::IsSwiftMangledName(
339+
name.GetStringRef())) {
337340
lldb_private::ConstString basename;
338341
bool is_method = false;
339342
ConstString mangled_name = mangled.GetMangledName();
@@ -346,6 +349,7 @@ void Symtab::InitNameIndexes() {
346349
else
347350
basename_to_index.Append(basename, value);
348351
}
352+
continue;
349353
}
350354
}
351355
#endif // LLDB_ENABLE_SWIFT

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)