diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2022-02-03 10:48:16 -0800 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2022-02-03 10:48:16 -0800 |
commit | e9a1946a1be197ada1bda4260e50aabeb07d4b26 (patch) | |
tree | 32cc095d92c8bab3419582f1cf760aac56e19bab | |
parent | 9f0ce07711d6202e11b0ec5761797a9e53c2e636 (diff) |
[lldb] Don't construct the demangled strings while indexing the symbol tableD118814
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
-rw-r--r-- | lldb/source/Core/Mangled.cpp | 17 | ||||
-rw-r--r-- | lldb/source/Symbol/Symtab.cpp | 4 | ||||
-rw-r--r-- | lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py | 4 |
3 files changed, 7 insertions, 18 deletions
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp index 60c1548dd636..ba3447020adb 100644 --- a/lldb/source/Core/Mangled.cpp +++ b/lldb/source/Core/Mangled.cpp @@ -214,25 +214,16 @@ bool Mangled::DemangleWithRichManglingInfo( case eManglingSchemeItanium: // We want the rich mangling info here, so we don't care whether or not // there is a demangled string in the pool already. - if (context.FromItaniumName(m_mangled)) { - // If we got an info, we have a name. Copy to string pool and connect the - // counterparts to accelerate later access in GetDemangledName(). - context.ParseFullName(); - m_demangled.SetStringWithMangledCounterpart(context.GetBufferRef(), - m_mangled); - return true; - } else { - m_demangled.SetCString(""); - return false; - } + return context.FromItaniumName(m_mangled); case eManglingSchemeMSVC: { // We have no rich mangling for MSVC-mangled names yet, so first try to // demangle it if necessary. if (!m_demangled && !m_mangled.GetMangledCounterpart(m_demangled)) { if (char *d = GetMSVCDemangledStr(m_mangled.GetCString())) { - // If we got an info, we have a name. Copy to string pool and connect - // the counterparts to accelerate later access in GetDemangledName(). + // Without the rich mangling info we have to demangle the full name. + // Copy it to string pool and connect the counterparts to accelerate + // later access in GetDemangledName(). m_demangled.SetStringWithMangledCounterpart(llvm::StringRef(d), m_mangled); ::free(d); diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp index 97dc31bc9766..61bc1b3b8d3c 100644 --- a/lldb/source/Symbol/Symtab.cpp +++ b/lldb/source/Symbol/Symtab.cpp @@ -328,8 +328,10 @@ void Symtab::InitNameIndexes() { const SymbolType type = symbol->GetType(); if (type == eSymbolTypeCode || type == eSymbolTypeResolver) { - if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name)) + if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name)) { RegisterMangledNameEntry(value, class_contexts, backlog, rmc); + continue; + } } } diff --git a/lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py b/lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py index 3455f21392dc..6f2f1c5b7cee 100644 --- a/lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py +++ b/lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py @@ -43,8 +43,6 @@ class DyldTrieSymbolsTestCase(TestBase): self.assertEqual(unstripped_Z3pat_symbols.GetSize(), 1) unstripped_pat_symbols = unstripped_target.FindSymbols("pat") self.assertEqual(unstripped_pat_symbols.GetSize(), 1) - unstripped_patint_symbols = unstripped_target.FindSymbols("pat(int)") - self.assertEqual(unstripped_patint_symbols.GetSize(), 1) unstripped_bar_symbols = unstripped_target.FindSymbols("bar") self.assertEqual(unstripped_bar_symbols.GetSize(), 1) @@ -77,8 +75,6 @@ class DyldTrieSymbolsTestCase(TestBase): self.assertEqual(stripped_Z3pat_symbols.GetSize(), 1) stripped_pat_symbols = stripped_target.FindSymbols("pat") self.assertEqual(stripped_pat_symbols.GetSize(), 1) - stripped_patint_symbols = stripped_target.FindSymbols("pat(int)") - self.assertEqual(stripped_patint_symbols.GetSize(), 1) # bar should have been strippped. We should not find it, or the # stripping went wrong. |