3 ms·
> If it's the former, I'd love to know why the frame stack version of the program would run more slowly. I believe it's the former and my understanding is tha
by wizeman 4y ago
> If it's the former, I'd love to know why the frame stack version of the program would run more slowly.
I believe it's the former and my understanding is that the stack frame version uses a register (RBP on x86-64) to keep track of the (start?) of the stack frame, which presumably helps in debugging / getting stack traces and profiling performance.
However, when not keeping track of the stack frame, the compiler can use the RBP register for storing other values, which means that the compiler has one more register it can use to avoid loading/storing values in memory (accessing memory is much slower than accessing registers).
Also, when not keeping track of the stack frame, I believe there is less of a need to store/restore the value of RBP at the beginning/end of functions, which also reduces code size and number of instructions executed, I think.
As far as I understand, those are the reasons for the slowdown.