Rust Brain Teasers: "Stacking Boxes" heap vs. stack performance explanation

Thank you! I’m inclined to agree, I’ll see if I can make that explanation a bit clearer for the next beta.

There’s really two things at play with stack vs. heap cache. One is locality: your stack is almost always in one of the cache levels because your program uses it constantly. The stack being tiny also helps with this: it’s easy to fit into the cache, so there’s an even higher probability that it will be there (and if it isn’t, it’s a fast operation to load a tiny stack frame into cache vs. an arbitrarily sized heap object).

Good catch - thank you. :slight_smile:

1 Like