[lld] 0e8fd36 - [lld-macho] Parallelize ObjFile::sourceFile() during STABS emission. (#222087)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 08:05:07 PDT 2026


Author: Liza Burakova
Date: 2026-09-14T11:05:01-04:00
New Revision: 0e8fd3609aae9dab8e24953a126c1a97871cc7fc

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

LOG: [lld-macho] Parallelize ObjFile::sourceFile() during STABS emission. (#222087)

This is part of the ld64.lld performance improvements tracked by #222068

Currently, SymtabSection::emitStabs() calls emitBeginSourceStab() it
passes in file->sourceFile(), which will call
ObjFile::sourceFile(). This method reads the component's root DIE, which
is a bottleneck when done serially as at this stage the DWARF sections
have not been parsed yet.

This commit parallelizes the calls to ObjFile::sourceFile(), as we
already have the file ids stable sorted.

AI tool use: this is one of the commits that was prototyped by AI. I
rewrote this commit and ran the benchmarking myself.

**Benchmark for mac_debug_component_sym_2**
LLD Baseline
Time (mean ± σ): 8.630 s ± 0.479 s [User: 7.170 s, System: 2.012 s]
  Range (min … max):    8.147 s …  9.661 s    20 runs

LLD Optimized
Time (mean ± σ): 8.149 s ± 0.373 s [User: 7.410 s, System: 2.206 s]
  Range (min … max):    7.804 s …  9.507 s    20 runs

LLD Baseline 2
Time (mean ± σ): 8.365 s ± 0.347 s [User: 7.097 s, System: 1.922 s]
  Range (min … max):    8.036 s …  9.146 s    20 runs

Added: 
    

Modified: 
    lld/MachO/SyntheticSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index c4277d54edd38..1f388b329aedf 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -1239,7 +1239,6 @@ void SymtabSection::emitStabs() {
     if (auto *defined = dyn_cast<Defined>(sym)) {
       // Excluded symbols should have been filtered out in finalizeContents().
       assert(defined->includeInSymtab);
-
       if (defined->isAbsolute())
         continue;
 
@@ -1263,6 +1262,14 @@ void SymtabSection::emitStabs() {
 
   llvm::stable_sort(symbolsNeedingStabs, llvm::less_second());
 
+  llvm::MapVector<ObjFile *, std::string> stabFiles;
+  for (const auto &[defined, fileId] : symbolsNeedingStabs) {
+    ObjFile *file = cast<ObjFile>(defined->originalIsec->getFile());
+    stabFiles[file] = "";
+  }
+  parallelForEach(stabFiles,
+                  [&](auto &it) { it.second = it.first->sourceFile(); });
+
   // Emit STABS symbols so that dsymutil and/or the debugger can map address
   // regions in the final binary to the source and object files from which they
   // originated.
@@ -1282,7 +1289,7 @@ void SymtabSection::emitStabs() {
         emitEndSourceStab();
       lastFile = file;
 
-      emitBeginSourceStab(file->sourceFile());
+      emitBeginSourceStab(stabFiles[file]);
       emitObjectFileStab(file);
     }
 


        


More information about the llvm-commits mailing list