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

Use faster any_hash logic in rb_hash #4916

Merged
merged 1 commit into from
Sep 30, 2021
Merged

Commits on Sep 30, 2021

  1. Use faster any_hash logic in rb_hash

    From the documentation of rb_obj_hash:
    
    > Certain core classes such as Integer use built-in hash calculations and
    > do not call the #hash method when used as a hash key.
    
    So if you override, say, Integer#hash it won't be used from rb_hash_aref
    and similar. This avoids method lookups in many common cases.
    
    This commit uses the same optimization in rb_hash, a method used
    internally and in the C API to get the hash value of an object. Usually
    this is used to build the hash of an object based on its elements.
    Previously it would always do a method lookup for 'hash'.
    
    This is primarily intended to speed up hashing of Arrays and Hashes,
    which call rb_hash for each element.
    
        compare-ruby: ruby 3.0.1p64 (2021-04-05 revision 0fb782e) [x86_64-linux]
        built-ruby: ruby 3.1.0dev (2021-09-29T02:13:24Z fast_hash d670bf88b2) [x86_64-linux]
        # Iteration per second (i/s)
    
        |                 |compare-ruby|built-ruby|
        |:----------------|-----------:|---------:|
        |hash_aref_array  |       1.008|     1.769|
        |                 |           -|     1.76x|
    jhawthorn committed Sep 30, 2021
    Configuration menu
    Copy the full SHA
    c49b171 View commit details
    Browse the repository at this point in the history