MARK CALLAGHAN <mdcallag@gmail.com> writes:
getcontext is slow because it saves everything --FP regs, SSE regs, signal handlers. It was safe for RethinkDB to skip saving them but
The expensive part is signal handlers, as it requires a system call.
they are not providing a library that can run in a wide variety of contexts. Why is it safe to skip them in this patch?
There is no need to save signal handlers, since we never change or use signal handlers inside a co-routine (or anywhere in the library). Eg. mysql_real_connect_cont() does not care if the application changed the signal handlers since mysql_real_connect_start(). FP/SSE registers are caller-save in the x86_64 ABI. This means _any_ function call can change them without having to save/restore them. On x86_64, the callee-save registers are rbp, rbx, r12, r13, r14, r15 (plus rip and rsp). So mysql_real_connect_start() will not change signal handlers despite the co-routines not saving/restoring them, since we never change signal handlers inside libmysql. mysql_real_connect_start() _may_ change FP/SSE regs, but so may normal mysql_real_connect() or any library function, according to the ABI. - Kristian.