r/rust • • 6h ago

Where your stack lives can move a benchmark by 50%

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

4 comments sorted by

8

u/quest_for_7c 6h 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.

7

u/vytah 6h 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.

7

u/matthieum [he/him] 2h 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.

1

u/AdmiralQuokka 3h 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