8000 YJIT: Replace Array#each only when YJIT is enabled by k0kubun · Pull Request #11955 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

YJIT: Replace Array#each only when YJIT is enabled #11955

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 10000 privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 4, 2024

Conversation

k0kubun
Copy link
Member
@k0kubun k0kubun commented Oct 26, 2024

This PR resurrects the C implementation of Array#each for the interpreter and lets YJIT use the Ruby one. To minimize incompatibilities between the interpreter and YJIT, it also introduces Primitive.attr! :c_trace to let Array#each act like a C method in backtraces.

It speeds up the interpreter on lobsters a little. While the rewrite of Array#each in Ruby #9533 did not slow down Array#each on the interpreter with microbenchmarks, it had a small impact on larger benchmarks.

before: ruby 3.4.0dev (2024-10-26T13:20:34Z master 484ea00d2e) +PRISM [x86_64-linux]
after: ruby 3.4.0dev (2024-10-28T10:43:42Z yjit-ruby-mode 192faf1882) +PRISM [x86_64-linux]

--------  -----------  ----------  ----------  ----------  -------------  ------------
bench     before (ms)  stddev (%)  after (ms)  stddev (%)  after 1st itr  before/after
lobsters  843.4        1.1         838.8       0.6         0.95           1.01
--------  -----------  ----------  ----------  ----------  -------------  ------------

@k0kubun k0kubun force-pushed the yjit-ruby-mode branch 4 times, most recently from b67e1c3 to e045b6b Compare October 27, 2024 08:28
@k0kubun k0kubun marked this pull request as ready for review October 28, 2024 15:55
@matzbot matzbot requested a review from a team October 28, 2024 15:55

This comment has been minimized.

Copy link
Member
@XrXr XrXr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure that once the Ruby implementation is subbed in, it's still a basic method, because we have code like the following for example in Enumerable#inject:

    if (iter == inject_op_i &&
        SYMBOL_P(op) &&
        RB_TYPE_P(obj, T_ARRAY) &&
        rb_method_basic_definition_p(CLASS_OF(obj), id_each)) {
        return ary_inject_op(obj, init, op);
    }

Copy link
Contributor
@maximecb maximecb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we are likely to port more runtime methods to Ruby (bring back Aaron's ports and add some more?), and that this may increase generated code size, I think it would be good to have a command line flag (or an environment variable?) so we can turn this on or off. This would allow us to test the impact on benchmarks and in production at various stages.

An environment variable might be easier for production?

@k0kubun
Copy link
Member Author
k0kubun commented Nov 1, 2024

I was so confused by the test-all failure that it took a while to fix it, but I finally fixed the test-all failure fd9a306.

We should make sure that once the Ruby implementation is subbed in, it's still a basic method, because we have code like the following for example in Enumerable#inject:

Fixed in d06ac2b

I think it would be good to have a command line flag (or an environment variable?)

Added --yjit-c-builtin fdade1e. A command line flag would be the most useful thing on yjit-bench, but a build flag is more useful for comparison on SFR. So I allowed YJIT_C_BUILTIN macro to switch it too.

@maximecb
Copy link
Contributor
maximecb commented Nov 4, 2024

Good work Kokubun! 👏

@maximecb maximecb merged commit 478e0fc into ruby:master Nov 4, 2024
138 checks passed
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

Successfully merging this pull request may close these issues.

3 participants
0