8000 perf: shrink `RelocationKindInfo` struct size by marxin · Pull Request #2603 · wild-linker/wild · GitHub
[go: up one dir, main page]

Skip to content

perf: shrink RelocationKindInfo struct size - #2603

Merged
marxin merged 6 commits into
wild-linker:mainfrom
marxin:perf-shrink-RelocationKindInfo
Sep 26, 2026
Merged

marxin merged 6 commits into
wild-linker:mainfrom
marxin:perf-shrink-RelocationKindInfo

Conversation

@marxin
@marxin marxin commented Sep 25, 2026
Copy link
Copy Markdown
Collaborator

Opening as a draft as the PR will deserve a bit more polishing, but sending to get a feedback from others. I noticed apply_relocation spends a lot of time copying the RelocationKindInfo (5x xmm register move to stack memory) at the place where we track previous relocation. With the PR, the size got reduced from 80B to 32B. I can measure ~1.5 speed-up on clang.release benchmark with 8 threads and got following poop numbers:

❯ poop './run-with /tmp/wild.before --threads=8' './run-with ~/Programming/wild/target/release-debug/wild --threads=8'
Benchmark 1 (67 runs): ./run-with /tmp/wild.before --threads=8
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          74.3ms ± 1.30ms    71.9ms … 77.4ms          0 ( 0%)        0%
  peak_rss           4.88MB ±  162KB    4.55MB … 5.29MB          0 ( 0%)        0%
  cpu_cycles         1.92G  ± 62.5M     1.83G  … 2.05G           0 ( 0%)        0%
  instructions       2.86G  ±  465K     2.86G  … 2.86G           0 ( 0%)        0%
  cache_references   73.1M  ± 1.75M     70.0M  … 76.6M           0 ( 0%)        0%
  cache_misses       9.96M  ±  199K     9.62M  … 10.4M           0 ( 0%)        0%
  branch_misses      5.87M  ± 11.7K     5.85M  … 5.91M           1 ( 1%)        0%
Benchmark 2 (68 runs): ./run-with ~/Programming/wild/target/release-debug/wild --threads=8
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          73.6ms ± 1.50ms    70.5ms … 78.1ms          1 ( 1%)          -  0.9% ±  0.6%
  peak_rss           7.31MB ±  336KB    6.51MB … 8.01MB          0 ( 0%)        💩+ 49.8% ±  1.8%
  cpu_cycles         1.89G  ± 61.8M     1.81G  … 2.07G           0 ( 0%)          -  1.1% ±  1.1%
  instructions       2.82G  ±  501K     2.82G  … 2.83G           1 ( 1%)        ⚡-  1.3% ±  0.0%
  cache_references   73.0M  ± 1.77M     70.4M  … 77.3M           0 ( 0%)          -  0.1% ±  0.8%
  cache_misses       9.98M  ±  216K     9.55M  … 10.3M           0 ( 0%)          +  0.2% ±  0.7%
  branch_misses      5.88M  ± 68.1K     5.84M  … 6.43M           2 ( 3%)          +  0.1% ±  0.3%

@davidlattimore @lapla-cogito can you please benchmark it a bit so that we have a better taste if it's worse doing the optimization.

@lapla-cogito
Copy link
Copy Markdown
Member

In my environment, the wall time was almost the same as the current main. However, looking at the results from your poop measurements, there seems to be a significant difference in RSS. I wasn't able to reproduce this difference in my environment 🤷

@davidlattimore
Copy link
Copy Markdown
Member

For zed-release I see a 1.81% +/- 0.42% reduction in wall time. For clang-release, the speedup is smaller at 0.22% +/- 0.07%. Although if I link clang-release with --threads=8 then I see a speedup of 1.07% +/- 0.07%.

There's definitely something funny looking with Martin's benchmark. It looks like it was run without --no-fork, but has a very large percentage change in peak RSS which makes me think perhaps it's comparing a release-debug build with a release build. Rustc does codegen differently when debug info is enabled (spilling extra variables to the stack), so it's not recommended to do that.

From a quick skim of the change, it seems like a change that makes sense to me and the benchmarks look worth it. Size::value looks a bit weird though. It seems to be a mix of sizes and bitmasks.

@mati865
mati865 commented Sep 25, 2026 •
Copy link
Copy Markdown
Member

For me with Clang without debug info benchmark, this is >1% improvement with 8 threads, and just a noise with all 32 threads. No RSS changes regardless if forking or not.

@marxin
marxin marked this pull request as ready for review September 26, 2026 11:11
@marxin
marxin commented Sep 26, 2026
Copy link
Copy Markdown
Collaborator Author

From a quick skim of the change, it seems like a change that makes sense to me and the benchmarks look worth it. Size::value looks a bit weird though. It seems to be a mix of sizes and bitmasks.

Nice, thank you all for the collected numbers. Might be the case the RSS diff is an artifact caused by me comparing release build w/ and w/o a debug-info.

@marxin
marxin commented Sep 26, 2026
Copy link
Copy Markdown
Collaborator Author

large percentage change in peak RSS which makes me think perhaps it's comparing a release-debug build with a release build.

Apparently, it's no caused by that - no that RSS of the parent Wild process is not much interesting to compare. With --no-fork, the numbers match:

❯ poop './run-with ~/Programming/wild/wild.before --threads=4 --no-fork' './run-with ~/Programming/wild/target/release-debug/wild --threads=4 --no-fork'
Benchmark 1 (51 runs): ./run-with ~/Programming/wild/wild.before --threads=4 --no-fork
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          99.3ms ± 2.26ms    94.7ms …  107ms          1 ( 2%)        0%
  peak_rss            594MB ±  658KB     593MB …  596MB          0 ( 0%)        0%
  cpu_cycles         1.59G  ± 34.9M     1.54G  … 1.67G           0 ( 0%)        0%
  instructions       2.86G  ±  377K     2.86G  … 2.86G           0 ( 0%)        0%
  cache_references   66.8M  ±  363K     66.3M  … 68.8M           3 ( 6%)        0%
  cache_misses       8.66M  ±  142K     8.44M  … 8.90M           0 ( 0%)        0%
  branch_misses      5.55M  ± 12.0K     5.53M  … 5.58M           0 ( 0%)        0%
Benchmark 2 (51 runs): ./run-with ~/Programming/wild/target/release-debug/wild --threads=4 --no-fork
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          98.0ms ± 2.01ms    94.8ms …  102ms          0 ( 0%)          -  1.3% ±  0.8%
  peak_rss            596MB ±  724KB     595MB …  598MB          0 ( 0%)          +  0.3% ±  0.0%
  cpu_cycles         1.57G  ± 35.2M     1.52G  … 1.64G           0 ( 0%)          -  1.4% ±  0.9%
  instructions       2.82G  ±  385K     2.82G  … 2.82G           0 ( 0%)        ⚡-  1.3% ±  0.0%
  cache_references   66.4M  ±  224K     66.0M  … 66.9M           0 ( 0%)          -  0.5% ±  0.2%
  cache_misses       8.67M  ±  137K     8.44M  … 8.91M           0 ( 0%)          +  0.1% ±  0.6%
  branch_misses      5.54M  ± 19.6K     5.53M  … 5.67M           1 ( 2%)          -  0.1% ±  0.1%

@marxin
marxin merged commit 995ac77 into wild-linker:main Sep 26, 2026
26 checks passed
@marxin
marxin deleted the perf-shrink-RelocationKindInfo branch September 26, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0