Hacker News new | ask | show | jobs
by Spivak 1698 days ago
So this one is counterintuitive. You only spend stack space for local variables that don’t fit in registers. If you in-line a function with lots of local variables into a function with lots of local variables you use more stack space. And then that additional stack space can’t be reclaimed until the function it was inlined into returns. So it’s more stack space used temporarily but less used on average.
1 comments

The same (and more) stack space will be used if it was called as a regular function, whether that's preserving registers across the call boundary or simply running out of registers. So this shouldn't save any space, temporarily or otherwise.
We’re not at all disagreeing. Calling vs inlining trades higher peak stack usage for (ideally) lower average stack usage.

Long running function calling short lived but high memory use function is a bad candidate for inlining because of that.