r/rust • • 23h ago

Where your stack lives can move a benchmark by 50%

https://heikoseeberger.de/2026-12-01-stack-position/
13 Upvotes

6 comments sorted by

16

u/quest_for_7c 23h ago

Author here.

We added timers to tellus, a benchmark got 55% slower, and the timers weren't the cause. An unaligned 16-byte copy on every message got slow whenever it straddled two memory pages, and that depended only on where the thread's stack started. The same binary ran 67% slower just because its stack lay 96 bytes deeper.

Happy to answer questions.

18

u/vytah 22h ago

Everyone who benchmarks code should watch this: https://www.youtube.com/watch?v=r-TLSBdHe1A

TL;DW 1. Memory layout had giant impact on performance, and it's beyond developer's control. 2. Causal relationships make recognizing bottlenecks non-trivial.

14

u/matthieum [he/him] 19h ago

For context, since I don't recognize Youtube URIs: this is the talk "Performance Matters" that Emergy Berger gave at Strange Loop in 2019.

In this talk he introduced:

  1. Stabilizer: a tool for reliable benchmarking. Notably shifting the start of the stack by injecting environment variables of different lengths.
  2. Coz: a Causal profiler.

6

u/AdmiralQuokka 19h ago

The Author is transparent about AI assistance, unfortunately only at the end of the text. Would be nice to have the disclaimer at the start, so readers can decide whether they want to read it or not.

Pangram reports the text as 74% AI-generated: https://www.pangram.com/history/10d22fa0-52ee-4814-b22f-4f1e17962afe

10

u/robertknight2 14h ago

Irrespective of one's views on AI generally, I really would advise people posting here to either avoid AI for writing technical posts or at least carefully edit what it produces. Otherwise you tend to get content which is unnecessarily difficult for readers to understand and a genuinely interesting subject can be obscured by poor writing.

1

u/SnooWoofers170 10h ago

Really good write-up. The A/A control is the part I'm going to copy - I compare builds with interleaved runs and medians, but I've never measured the harness against itself, so a "5% faster" number from me is basically unverified.

One thing I couldn't tell from the post: was the page-split penalty ever reproducible on the x86_64 jobs, or only on your aarch64 machine? All four inconclusive null runs landing on x86_64 made me wonder.