-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle throw
instruction without exiting in YJIT
#504
Comments
The trace of
Examples: I was primarily interested in directly jumping from JIT code to JIT code. However, it doesn't seem safe if there's a C method frame in between, which seems like the case for those examples (i.e. So my current idea is to take multiple steps as follows:
|
Even if we can just eliminate the interpreter exits, it would be a win. It's not just the entry/exit that slow us down, it's also that it can take a while to get back into JIT code. That only happens at JIT entry points, so if you go through a bunch of
If you could compare the current C stack pointer vs the stack pointer at the return, it might be possible to detect that 🤔 Might be other strategies we could use too... Like, if we could somehow know that the rescue block is in the caller directly, then we only need to check that the You could even, generate a little unrolled loop that walks the stack up to N==8 frames deep, and if it fails, it side-exits to the interpreter? |
Based on the fact that |
Out of curiosity I created a throw instruction microbenchmark: Shopify/yjit-bench#199 While testing that, I also tested replacing the throw instruction by a regular return and uh, the results are interesting. With throw, YJIT enabled:
With return, YJIT enabled:
So the overhead of |
* Test existing behavior Typing Ctrl-D ends editing but typing <Del> does not. Also renamed a test that is not testing ed_delete_next_char but key_delete. * Check if line empty first in em_delete By distributivity of AND over OR, we can factor out this condition. This will make the next commit simpler. * Use em_delete in key_delete When the editing mode is emacs, use `em_delete` in `key_delete`. We need to add a condition though to `em_delete`, because it implements both `delete-char` and `end-of-file`. We only want the `end-of-file` behavior is the key is really Ctrl-D. This matches the behavior of the <Del> key with readline, i.e. deleting the next character if there is one, but not moving the cursor, while not finishing the editing if there are no characters.
ruby#8171 basically solved the problem of exiting JIT code on |
Thanks to the work Jimmy has been doing closing the exits in
send
, we are very close to hitting 90%+ratio_in_yjit
on the liquid benchmark, and send is no longer at the top of the exit ops:Kokubun has expressed interest in tackling this one.
In some ways, throw behaves like a return, and so some dynamic dispatch strategy might be needed. I don't know the exact way that
throw
is implemented in CRuby, but I imagine that there is a function that can tell us where to throw to (which ISEQ/pc to jump to). A little cache with side-exits could then potentially be implemented to handle that.Does the interpreter currently use some kind of a cache for throw? How does it find out where to jump to?
The text was updated successfully, but these errors were encountered: