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

Liza Burakova via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 14:09:37 PDT 2026


================
@@ -1263,10 +1262,22 @@ void SymtabSection::emitStabs() {
 
   llvm::stable_sort(symbolsNeedingStabs, llvm::less_second());
 
+  std::vector<ObjFile *> stabFiles;
+  for (const SortingPair &pair : symbolsNeedingStabs) {
+    ObjFile *file = cast<ObjFile>(pair.first->originalIsec->getFile());
+    if (stabFiles.empty() || stabFiles.back() != file)
+      stabFiles.push_back(file);
+  }
+  std::vector<std::string> stabSourceFiles(stabFiles.size());
+  parallelFor(0, stabFiles.size(), [&](size_t i) {
+    stabSourceFiles[i] = stabFiles[i]->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.
   InputFile *lastFile = nullptr;
+  size_t stabFileIdx = 0;
   for (SortingPair &pair : symbolsNeedingStabs) {
----------------
liza371 wrote:

I tried this approach but noticed that we don't really see as big of a performance win

```
Baseline
Time (mean ± σ):      8.664 s ±  0.549 s    [User: 7.200 s, System: 2.209 s]
  Range (min … max):    8.177 s … 10.564 s    20 runs

New loop
Time (mean ± σ):      8.547 s ±  0.288 s    [User: 7.685 s, System: 2.341 s]
  Range (min … max):    8.143 s …  9.223 s    20 runs

```

I did change `stabSourceFiles` so now its populated based on the fileID iterator, and that replaces `stabSourceFiles[stabFileIdx++]` with `stabSourceFiles[file->id]`, and that seems to get us a bit more of a win.

```
Baseline
  Time (mean ± σ):      8.499 s ±  0.468 s    [User: 7.137 s, System: 2.031 s]
  Range (min … max):    8.034 s … 10.171 s    20 runs

Iterator
  Time (mean ± σ):      8.442 s ±  0.220 s    [User: 7.642 s, System: 2.225 s]
  Range (min … max):    8.193 s …  8.889 s    20 runs

Baseline
Time (mean ± σ):      8.710 s ±  0.400 s    [User: 7.181 s, System: 2.083 s]
  Range (min … max):    8.158 s …  9.714 s    20 runs
```


https://github.com/llvm/llvm-project/pull/222087


More information about the llvm-commits mailing list