[lld] 0baf13e - [lld/mac] Parallelize code signature computation
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 21 17:41:52 PDT 2022
Author: Nico Weber
Date: 2022-06-21T20:41:35-04:00
New Revision: 0baf13e282abe226069d9e18ca60dc63dfcbdb28
URL: https://github.com/llvm/llvm-project/commit/0baf13e282abe226069d9e18ca60dc63dfcbdb28
DIFF: https://github.com/llvm/llvm-project/commit/0baf13e282abe226069d9e18ca60dc63dfcbdb28.diff
LOG: [lld/mac] Parallelize code signature computation
According to ministat, this is a small but measurable speedup
(using the repro in PR56121):
N Min Max Median Avg Stddev
x 10 3.7439518 3.7783802 3.7730219 3.7655502 0.012375226
+ 10 3.6149218 3.692198 3.6519327 3.6502951 0.025905601
Difference at 95.0% confidence
-0.115255 +/- 0.0190746
-3.06078% +/- 0.506554%
(Student's t, pooled s = 0.0203008)
(Without 858e8b17f7365, this change here to use parallelFor is an 18% speedup,
and doing 858e8b17f7365 on top of this change is just a 2.55% +/- 0.58% win.
Doing both results in a total speedup of 20.85% +/- 0.44%.)
Differential Revision: https://reviews.llvm.org/D128298
Added:
Modified:
lld/MachO/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 378cf6b23947..4d7256e847fa 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -22,6 +22,7 @@
#include "llvm/Support/EndianStream.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/LEB128.h"
+#include "llvm/Support/Parallel.h"
#include "llvm/Support/Path.h"
#if defined(__APPLE__)
@@ -1247,11 +1248,11 @@ void CodeSignatureSection::writeHashes(uint8_t *buf) const {
// NOTE: Changes to this functionality should be repeated in llvm-objcopy's
// MachOWriter::writeSignatureData.
uint8_t *hashes = buf + fileOff + allHeadersSize;
- for (uint64_t i = 0; i < getBlockCount(); ++i) {
+ parallelFor(0, getBlockCount(), [&](size_t i) {
sha256(buf + i * blockSize,
std::min(static_cast<size_t>(fileOff - i * blockSize), blockSize),
hashes + i * hashSize);
- }
+ });
#if defined(__APPLE__)
// This is macOS-specific work-around and makes no sense for any
// other host OS. See https://openradar.appspot.com/FB8914231
More information about the llvm-commits
mailing list