From b0572abf72fd4aafbb56bc41350e41bdfd96cdde Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Tue, 1 Jun 2021 21:52:31 -0700 Subject: Improve performance when parsing symbol tables in mach-o files. Some larger projects were loading quite slowly with the current LLDB on macOS and macOS simulator builds. I did some instrument traces and found 3 main culprits: - a LLDB timer that was put into a function that was called too often - a std::set that was keeping track of the address of symbols that were already added - a unnamed function generator in ObjectFile that was going slow due to allocations In order to see this in action I ran the latest LLDB on a large application with many frameworks using the following method: (lldb) script import time; start_time = time.perf_counter() (lldb) file Large.app (lldb) script print(time.perf_counter() - start_time) I first range "sudo purge" to clear the system file caches to simulate a cold startup of the debugger, followed by two iterations with warm file caches. Prior to this fix I was seeing the following timings: 17.68 (cold) 14.56 (warm 1) 14.52 (warm 2) After this fix I was seeing: 11.32 (cold) 8.43 (warm 1) 8.49 (warm 2) Differential Revision: https://reviews.llvm.org/D103504 --- lldb/source/Symbol/ObjectFile.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lldb/source/Symbol/ObjectFile.cpp') diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp index f5dcbc5467f7..b0fdd50b3c0f 100644 --- a/lldb/source/Symbol/ObjectFile.cpp +++ b/lldb/source/Symbol/ObjectFile.cpp @@ -617,11 +617,13 @@ ObjectFile::GetSymbolTypeFromName(llvm::StringRef name, } ConstString ObjectFile::GetNextSyntheticSymbolName() { - StreamString ss; + llvm::SmallString<256> name; + llvm::raw_svector_ostream os(name); ConstString file_name = GetModule()->GetFileSpec().GetFilename(); - ss.Printf("___lldb_unnamed_symbol%u$$%s", ++m_synthetic_symbol_idx, - file_name.GetCString()); - return ConstString(ss.GetString()); + ++m_synthetic_symbol_idx; + os << "___lldb_unnamed_symbol" << m_synthetic_symbol_idx << "$$" + << file_name.GetStringRef(); + return ConstString(os.str()); } std::vector -- cgit v1.2.3