4 ms·
What's the runtime overhead on this? Aren't setjmp and longjmp considered slow?
by bajsejohannes 13y ago
What's the runtime overhead on this? Aren't setjmp and longjmp considered slow?
- ajross 13y agoset/longjmp are full context switches, so they need to write out all relevant registers to memory. More to the point the "context" being saved here is the full C stack, so in addition to the space for the registers you also need to allocate memory for the stacks to which you are going to swtich. With a more constrained language, the compiler would be able to do cleaner analysis to save off only the subset of closed-over data. Most functions like this don't ever need to return all the way up to the thread top, they just work with a few local variables. That said, saving/restoring a few hundred bytes of registers and allocating a page for a small stack are hardly "slow" operations, so I wouldn't view performance as a real issue here.