Skip to content
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

YJIT: reduce the frequency of RUBY_VM_CHECK_INTS(ec) #530

Open
maximecb opened this issue Sep 5, 2023 · 0 comments
Open

YJIT: reduce the frequency of RUBY_VM_CHECK_INTS(ec) #530

maximecb opened this issue Sep 5, 2023 · 0 comments

Comments

@maximecb
Copy link

maximecb commented Sep 5, 2023

I was looking at the disassembly and saw we're doing a lot of RUBY_VM_CHECK_INTS(ec) all over the place. We need to check for interrupts semi-regularly, but presumably we could skip some, gain some performance, reduce code size a bit, and still be fine.

There's already one small optimization for this in YJIT: forward branches don't check for interrupts, because we know we're making forward progress in an ISEQ, while backwards branches do, because they could be loops.

I'm wondering what other heuristics we could come up with. Some possibilities:

  • Could we skip the check for some C calls? If so, which ones?
  • Could we skip the return check if we know we just returned from a call?
    • It has to happen often that we have multiple returns in a row

The main problem that I see is that it seems tricky to come up with a good heuristic. I think we could probably skip the check for most C calls, but are there some C calls where this wouldn't be safe?

Potentially, we could also skip the check for all returns or for all calls, simply because, every return has to match up with a call and we can't have infinite recursion. However, if we want to skip the check for some calls/returns but not all, it becomes trickier to find a robust heuristic.

For instance, if we want to skip the check when there is a send preceding a return, we have the issue that we don't necessarily know if there is always a send preceding said return, because there may be a branch that hasn't been compiled yet. We would need a little ISEQ-level analysis to be completely sure that control-flow can't come to the return without first passing through a send.

Tagging @jhawthorn @k0kubun and @XrXr to start the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant