From: Eric Wong Date: 2021-04-04T20:40:48+00:00 Subject: [ruby-core:103208] Re: [Ruby master Feature#5446] at_fork callback API eregontp@gmail.com wrote: > > Is there a way to expose Ruby methods/procs as C function pointers with JIT? > > @normalperson That feels very hacky to me. fork() seems hacky now that Ractor exists, and Process.spawn/popen/system use vfork (along with cloexec being the default) > JIT'ing a function which is only called once seems suboptimal > (and difficult to do before it's even called once). > Also some Ruby state likely needs to be restored before > running any `after_fork` hook. Maybe not "JIT", but just-ahead-of-time or on-demand-compiled. Something like "Proc#compile_to_c" returning an Integer pointer. It would be generally useful for Fiddle to pass callbacks implemented in Ruby around, but I agree tricky to get right because Ruby state could be indeterminate when the C function is called... > @byroot I agree, we should at least have `after_fork` (or `at_fork(when, &block)`). For projects where I'm stuck having to fork, I find "prepare" (before_fork) just as useful. I've only used "parent" (after fork), once, however. > Honestly I don't understand why we don't have this yet, it's > obviously needed and every forking webserver out there ends up > having its own hook. With Ractor, perhaps fork() shouldn't be encouraged/promoted, anymore. > And BTW the current workaround of checking pid is slower also > on platforms not supporting `fork`, so it is inefficient for > all platforms and webservers. Agreed. Unsubscribe: