Optimize GetCompileUnitContainingDIE with a lookup table
For large executable with debug symbols GetCompileUnitContainingDIE
took most of the time spent on DWARF parsing. Optimize it from linear
search to a logarithmic search with a lookup table.
Differential D11390
Optimize GetCompileUnitContainingDIE with a lookup table clayborg on Jul 21 2015, 8:45 AM. Authored by
Details
Optimize GetCompileUnitContainingDIE with a lookup table For large executable with debug symbols GetCompileUnitContainingDIE
Diff Detail Event TimelineComment Actions I'll let Greg weigh in on the actual details, but if as I understand the patch, the m_die_to_index_map only stored CU dies, can you make the name of the ivar indicate that fact? Comment Actions Yes it only contains compile unit indexes. The reason I haven't included in the name because the class focuses on compile units, but I can add it if you prefer it that way. Comment Actions No need for an extra map. A local C++ guru a while back told me about being able to use a comparison function with two different types if you use std::lower_bound() or std::upper_bound(). Since m_compiler_units is sorted, we can just do: static bool CompileUnitOffsetLessThan (dw_offset_t die_offset, const DWARFCompileUnitSP& cu_sp) { return die_offset < cu_sp->GetOffset(); } DWARFCompileUnitSP DWARFDebugInfo::GetCompileUnitContainingDIE(dw_offset_t die_offset) { DWARFCompileUnitSP cu_sp; if (die_offset != DW_INVALID_OFFSET) { ParseCompileUnitHeadersIfNeeded(); // Watch out for single compile unit executable as they are pretty common const size_t num_cus = m_compile_units.size(); if (num_cus == 1) { if (m_compile_units[0]->ContainsDIEOffset(die_offset)) cu_sp = m_compile_units[0]; } else if (num_cus) { CompileUnitColl::const_iterator end_pos = m_compile_units.end(); CompileUnitColl::const_iterator begin_pos = m_compile_units.begin(); CompileUnitColl::const_iterator pos = std::upper_bound(begin_pos, end_pos, die_offset, CompileUnitOffsetLessThan); if (pos != begin_pos) { --pos; if ((*pos)->ContainsDIEOffset(die_offset)) cu_sp = *pos; } } } return cu_sp; } Try out the changes and make sure they work and then switch to using the code above. Comment Actions I actually checked my changes in with: % svn commit |