4 ms·
So first let me say I assume there's a good answer to this. I'm asking to find out what it is, not as any sort of criticism. Why not leave the segmented stacks
by jerf 12y ago
So first let me say I assume there's a good answer to this. I'm asking to find out what it is, not as any sort of criticism.
Why not leave the segmented stacks, and simply refuse to shrink them? When a stack grows, then shrinks back down, you could just leave yourself a note at the very end of the stack about where the next stack segment is, so you won't be reallocating. Plus you could start trimming off the end of the stacks if you shrank some % of the way back down to zero.
- pcwalton 12y agoIt's not just the allocation—just the cost of switching between stack segments is really expensive. Function calls are 2 ns on most architectures; any overhead can easily make that 5x or 10x slower.
- jerf 12y agoThanks. I know it's the "wrong language" for you, but after years of working in Perl and occasionally profiling it, it was a shock to switch to Go and profile anything in "nanoseconds". To see even a "microsecond" appear in Perl code is often a bit of a pleasant surprise. To some extent I'm still not used to being concerned that adding 2ns to a code path might have noticeable performance impacts....