Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

you can mitigate the cost by not 'call'-ing into your coroutine switch function but inlining the code into the surrounding coroutine. As a bonus you get a bit better branch prediction on your yield because distinct yields will share less state.

Of course there is always going to be a penality for stackful coroutines that yield deep into a callstack.



Unfortunately, this is very difficult to do above the assembly level because it requires a custom calling convention that doesn’t yet seem to be supported by any systems programming language compiler. You have to use an assembler macro, or pipe the assembler output through sed, to patch the call and ret instructions:

https://stackoverflow.com/questions/43894511


GCC inline assembly can be coerced to do the right thing.


It’s not great, though. Modern C compilers will generally fight you if you try to subvert structured programming.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: