2 ms·
> Stack switching doesn't take more than a few machine instructions. In Rust we found that stack switching was really slow, even when fully optimized to that s
by pcwalton 11y ago
> Stack switching doesn't take more than a few machine instructions.
In Rust we found that stack switching was really slow, even when fully optimized to that scheme. CPUs really don't like it. We thought "it was only a few instructions; how bad can it be"; turns out that any function call overhead can quickly add up to 2x or more overall performance penalties in some programs.
See the performance numbers in this thread for cgo (using the same technique) [1]. According to the first benchmark, calling the function via cgo is 16x slower. You're at 161ns for a no-op function call.
Consider that the cost of a syscall can be below 100ns [2]. The overhead can add up quite a bit!
[1]: https://groups.google.com/forum/#!topic/golang-nuts/RTtMsgZi88Q https://groups.google.com/forum/#!topic/golang-nuts/RTtMsgZi...
[2]: http://forum.osdev.org/viewtopic.php?p=209429&sid=9bcec5b68408721f24121699cc7d99f1#p209429 http://forum.osdev.org/viewtopic.php?p=209429&sid=9bcec5b684...