Author: adrian Date: Thu Oct 10 10:59:15 2019 New Revision: 374401 URL: http://llvm.org/viewvc/llvm-project?rev=374401&view=rev Log: Speed up accelerator table lookups
When debugging a large program like clang and doing "frame variable *this", the ValueObject pretty printer is doing hundreds of scoped FindTypes lookups. The ones that take longest are the ones where the DWARFDeclContext ends in something like ::Iterator which produces many false positives that need to be filtered out *after* extracting the DIEs. This patch demonstrates a way to filter out false positives at the accerator table lookup step. With this patch lldb clang-10 -o "b EmitFunctionStart" -o r -o "f 2" -o "fr v *this" -b -- ... goes (in user time) from 5.6s -> 4.8s or (in wall clock) from 6.9s -> 6.0s. Differential Revision: https://reviews.llvm.org/D68678 Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/Makefile lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/TestCPPAccelerator.py lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/a.cpp lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/b.cpp lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/c.cpp lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/d.cpp lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/e.cpp lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/f.cpp lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/g.cpp lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/main.cpp lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/source.h Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/Makefile?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/Makefile (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/Makefile Thu Oct 10 10:59:15 2019 @@ -0,0 +1,7 @@ +# There is no guaranteed order in which the linker will order these +# files, so we just have a lot of them to make it unlikely that we hit +# the right one first by pure luck. + +CXX_SOURCES := main.cpp a.cpp b.cpp c.cpp d.cpp e.cpp f.cpp g.cpp + +include Makefile.rules Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/TestCPPAccelerator.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/TestCPPAccelerator.py?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/TestCPPAccelerator.py (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/TestCPPAccelerator.py Thu Oct 10 10:59:15 2019 @@ -0,0 +1,31 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class CPPAcceleratorTableTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIf(debug_info=no_match(["dwarf"])) + def test(self): + """Test that type lookups fail early (performance)""" + self.build() + logfile = self.getBuildArtifact('dwarf.log') + self.expect('log enable dwarf lookups -f' + logfile) + target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, 'break here', lldb.SBFileSpec('main.cpp')) + # Pick one from the middle of the list to have a high chance + # of it not being in the first file looked at. + self.expect('frame variable inner_d') + + log = open(logfile, 'r') + n = 0 + for line in log: + if re.findall(r'[abcdefg]\.o: FindByNameAndTag\(\)', line): + self.assertTrue("d.o" in line) + n += 1 + + self.assertEqual(n, 1, log) Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/a.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/a.cpp?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/a.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/a.cpp Thu Oct 10 10:59:15 2019 @@ -0,0 +1,2 @@ +#include "source.h" +CLASS(A) Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/b.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/b.cpp?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/b.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/b.cpp Thu Oct 10 10:59:15 2019 @@ -0,0 +1,2 @@ +#include "source.h" +CLASS(B) Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/c.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/c.cpp?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/c.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/c.cpp Thu Oct 10 10:59:15 2019 @@ -0,0 +1,2 @@ +#include "source.h" +CLASS(C) Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/d.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/d.cpp?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/d.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/d.cpp Thu Oct 10 10:59:15 2019 @@ -0,0 +1,2 @@ +#include "source.h" +CLASS(D) Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/e.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/e.cpp?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/e.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/e.cpp Thu Oct 10 10:59:15 2019 @@ -0,0 +1,2 @@ +#include "source.h" +CLASS(E) Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/f.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/f.cpp?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/f.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/f.cpp Thu Oct 10 10:59:15 2019 @@ -0,0 +1,2 @@ +#include "source.h" +CLASS(F) Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/g.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/g.cpp?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/g.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/g.cpp Thu Oct 10 10:59:15 2019 @@ -0,0 +1,2 @@ +#include "source.h" +CLASS(G) Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/main.cpp?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/main.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/main.cpp Thu Oct 10 10:59:15 2019 @@ -0,0 +1,28 @@ +#define CLASS(NAME) \ + class NAME { \ + public: \ + struct Inner; \ + Inner *i = nullptr; \ + }; \ +NAME::Inner &getInner##NAME(); + +CLASS(A) +CLASS(B) +CLASS(C) +CLASS(D) +CLASS(E) +CLASS(F) +CLASS(G) + +int main() +{ + A::Inner &inner_a = getInnerA(); + B::Inner &inner_b = getInnerB(); + C::Inner &inner_c = getInnerC(); + D::Inner &inner_d = getInnerD(); + E::Inner &inner_e = getInnerE(); + F::Inner &inner_f = getInnerF(); + G::Inner &inner_g = getInnerG(); + + return 0; // break here +} Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/source.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/source.h?rev=374401&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/source.h (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/accelerator-table/source.h Thu Oct 10 10:59:15 2019 @@ -0,0 +1,12 @@ +#define CLASS(NAME) \ + class NAME { \ + public: \ + class Inner { \ + int j = #NAME[0]; \ + }; \ + Inner *i = nullptr; \ + }; \ + \ + static NAME::Inner inner; \ + static NAME obj; \ + NAME::Inner &getInner##NAME() { return inner; } Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp?rev=374401&r1=374400&r2=374401&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp Thu Oct 10 10:59:15 2019 @@ -110,6 +110,7 @@ void AppleDWARFIndex::GetTypes(const DWA const bool has_qualified_name_hash = m_apple_types_up->GetHeader().header_data.ContainsAtom( DWARFMappedHash::eAtomTypeQualNameHash); + const ConstString type_name(context[0].name); const dw_tag_t tag = context[0].tag; if (has_tag && has_qualified_name_hash) { @@ -119,12 +120,32 @@ void AppleDWARFIndex::GetTypes(const DWA m_module.LogMessage(log, "FindByNameAndTagAndQualifiedNameHash()"); m_apple_types_up->FindByNameAndTagAndQualifiedNameHash( type_name.GetStringRef(), tag, qualified_name_hash, offsets); - } else if (has_tag) { + return; + } + + if (has_tag) { + // When searching for a scoped type (for example, + // "std::vector<int>::const_iterator") searching for the innermost + // name alone ("const_iterator") could yield many false + // positives. By searching for the parent type ("vector<int>") + // first we can avoid extracting type DIEs from object files that + // would fail the filter anyway. + if (!has_qualified_name_hash && (context.GetSize() > 1) && + (context[1].tag == DW_TAG_class_type || + context[1].tag == DW_TAG_structure_type)) { + DIEArray class_matches; + m_apple_types_up->FindByName(context[1].name, class_matches); + if (class_matches.empty()) + return; + } + if (log) m_module.LogMessage(log, "FindByNameAndTag()"); m_apple_types_up->FindByNameAndTag(type_name.GetStringRef(), tag, offsets); - } else - m_apple_types_up->FindByName(type_name.GetStringRef(), offsets); + return; + } + + m_apple_types_up->FindByName(type_name.GetStringRef(), offsets); } void AppleDWARFIndex::GetNamespaces(ConstString name, DIEArray &offsets) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits