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: Optimize Integer#succ #9519

Merged
merged 1 commit into from Jan 15, 2024
Merged

YJIT: Optimize Integer#succ #9519

merged 1 commit into from Jan 15, 2024

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Jan 13, 2024

We use Integer#succ when we rewrite loop methods in Ruby (e.g. Integer#times and Array#each) because opt_succ (i = i.succ) is faster to dispatch on the interpreter than putobject 1; opt_plus (i += 1).

Since YJIT currently doesn't optimize Integer#succ, it's rather slower than opt_plus. This PR fixes this problem to improve the performance of Array#each when it's rewritten in Ruby.

This also speeds up Integer#times on YJIT.

$ benchmark-driver benchmark/loop_times.rb -v --chruby 'before::before --yjit-call-threshold=1;after::after --yjit-call-threshold=1'
before: ruby 3.4.0dev (2024-01-13T00:28:26Z master f7178045bb) +YJIT [x86_64-linux]
after: ruby 3.4.0dev (2024-01-13T01:11:20Z yjit-succ c27641f431) +YJIT [x86_64-linux]
Calculating -------------------------------------
                         before       after
          loop_times      8.963      21.565 i/s -       1.000 times in 0.111565s 0.046371s

Comparison:
                       loop_times
               after:        21.6 i/s
              before:         9.0 i/s - 2.41x  slower

@maximecb maximecb merged commit 5e61cc2 into ruby:master Jan 15, 2024
97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants