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

Optimize Hash methods with Kernel#hash #10160

Merged
merged 1 commit into from
Mar 1, 2024
Merged

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Mar 1, 2024

rb_obj_hash is leaf. You don't need to push a frame when you dispatch that method.

before: ruby 3.4.0dev (2024-03-01T18:03:00Z master 661f9e6d03) [x86_64-linux]
after: ruby 3.4.0dev (2024-03-01T18:22:33Z kernel-hash 7b226d427c) [x86_64-linux]
Calculating -------------------------------------
                         before       after
      hash.key?(obj)    40.595M     58.930M i/s -     30.000M times in 0.739008s 0.509077s

Comparison:
                   hash.key?(obj)
               after:  58930238.8 i/s
              before:  40594941.2 i/s - 1.45x  slower

This seems to speed up railsbench:

before: ruby 3.4.0dev (2024-03-01T18:03:00Z master 661f9e6d03) [x86_64-linux]
after: ruby 3.4.0dev (2024-03-01T18:22:33Z kernel-hash 7b226d427c) [x86_64-linux]

----------  -----------  ----------  ----------  ----------  -------------  ------------
bench       before (ms)  stddev (%)  after (ms)  stddev (%)  after 1st itr  before/after
railsbench  4241.8       0.5         4213.9      0.4         1.01           1.01
----------  -----------  ----------  ----------  ----------  -------------  ------------
before: ruby 3.4.0dev (2024-03-01T18:03:00Z master 661f9e6d03) +YJIT [x86_64-linux]
after: ruby 3.4.0dev (2024-03-01T18:22:33Z kernel-hash 7b226d427c) +YJIT [x86_64-linux]

----------  -----------  ----------  ----------  ----------  -------------  ------------
bench       before (ms)  stddev (%)  after (ms)  stddev (%)  after 1st itr  before/after
railsbench  2443.5       0.8         2405.8      0.8         0.99           1.02
----------  -----------  ----------  ----------  ----------  -------------  ------------

This comment was marked as spam.

@k0kubun k0kubun marked this pull request as ready for review March 1, 2024 19:16
@k0kubun k0kubun merged commit 70de3b1 into ruby:master Mar 1, 2024
96 checks passed
@k0kubun k0kubun deleted the kernel-hash branch March 1, 2024 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant