[Lldb-commits] [lldb] b7d807d - [lldb] parallelize calling of Module::PreloadSymbols()

Luboš Luňák via lldb-commits lldb-commits at lists.llvm.org
Wed May 4 11:00:08 PDT 2022


Author: Luboš Luňák
Date: 2022-05-04T19:58:25+02:00
New Revision: b7d807dbcff0d9df466e0312b4fef57178d207be

URL: https://github.com/llvm/llvm-project/commit/b7d807dbcff0d9df466e0312b4fef57178d207be
DIFF: https://github.com/llvm/llvm-project/commit/b7d807dbcff0d9df466e0312b4fef57178d207be.diff

LOG: [lldb] parallelize calling of Module::PreloadSymbols()

If LLDB index cache is enabled and everything is cached, then loading of debug
info is essentially single-threaded, because it's done from PreloadSymbols()
called from GetOrCreateModule(), which is called from a loop calling
LoadModuleAtAddress() in DynamicLoaderPOSIXDYLD. Parallelizing the entire
loop could be unsafe because of GetOrCreateModule() operating on a module
list, so instead move only the PreloadSymbols() call to Target::ModulesDidLoad()
and parallelize there, which should be safe.

This may greatly reduce the load time if the debugged program uses a large
number of binaries (as opposed to monolithic programs where this presumably
doesn't make a difference). In my specific case of LibreOffice Calc this reduces
startup time from 6s to 2s.

Differential Revision: https://reviews.llvm.org/D122975

Added: 
    

Modified: 
    lldb/source/Target/Target.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index ed733f2645c3a..d6ad333957e11 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include <memory>
 #include <mutex>
@@ -1623,6 +1624,17 @@ void Target::NotifyModulesRemoved(lldb_private::ModuleList &module_list) {
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+    if (GetPreloadSymbols()) {
+      // Try to preload symbols in parallel.
+      llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
+      auto preload_symbols_fn = [&](size_t idx) {
+        ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+        module_sp->PreloadSymbols();
+      };
+      for (size_t idx = 0; idx < num_images; ++idx)
+        task_group.async(preload_symbols_fn, idx);
+      task_group.wait();
+    }
     for (size_t idx = 0; idx < num_images; ++idx) {
       ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
       LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2182,6 @@ ModuleSP Target::GetOrCreateModule(const ModuleSpec &module_spec, bool notify,
           });
         }
 
-        // Preload symbols outside of any lock, so hopefully we can do this for
-        // each library in parallel.
-        if (GetPreloadSymbols())
-          module_sp->PreloadSymbols();
-
         llvm::SmallVector<ModuleSP, 1> replaced_modules;
         for (ModuleSP &old_module_sp : old_modules) {
           if (m_images.GetIndexForModule(old_module_sp.get()) !=


        


More information about the lldb-commits mailing list