[lld] ELF: Switch to parallelSort for RELR relocations. (PR #138370)
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Fri May 2 17:26:31 PDT 2025
https://github.com/pcc created https://github.com/llvm/llvm-project/pull/138370
For firefox-x64 one of the more time consuming parts
of finalizeSections() was the call to llvm::sort in
RelrSection::updateAllocSize(). Switching that to use parallelSort
yielded the following improvement on firefox-x64 with ldflags -S on
an Apple M2 Ultra:
```
N Min Max Median Avg Stddev
x 512 1.1446024 1.2462944 1.1918706 1.1929871 0.016145
+ 512 1.1142867 1.2350058 1.1858642 1.1858839 0.016219708
Difference at 95.0% confidence
-0.00710318 +/- 0.00198234
-0.595412% +/- 0.166166%
(Student's t, pooled s = 0.0161824)
```
>From 173ed5860651c37c8601926a5fe13fa609272cbe Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Fri, 2 May 2025 17:26:17 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.6-beta.1
---
lld/ELF/SyntheticSections.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 2531227cb99b7..eceb297dbfc0d 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2111,7 +2111,7 @@ template <class ELFT> bool RelrSection<ELFT>::updateAllocSize(Ctx &ctx) {
std::unique_ptr<uint64_t[]> offsets(new uint64_t[relocs.size()]);
for (auto [i, r] : llvm::enumerate(relocs))
offsets[i] = r.getOffset();
- llvm::sort(offsets.get(), offsets.get() + relocs.size());
+ llvm::parallelSort(offsets.get(), offsets.get() + relocs.size());
// For each leading relocation, find following ones that can be folded
// as a bitmap and fold them.
More information about the llvm-commits
mailing list