Optimize calls to `Kernel#hash` by marcandre · Pull Request #3987 · ruby/ruby · GitHub
Skip to content

Optimize calls to Kernel#hash - #3987

Merged
nurse merged 1 commit into
ruby:masterfrom
marcandre:hash_optimize
Dec 24, 2020
Merged

nurse merged 1 commit into
ruby:masterfrom
marcandre:hash_optimize

Conversation

@marcandre

Copy link
Copy Markdown
Member

This avoids recursive checks when the hash method of an object isn't specialized.

@marcandre

marcandre commented Dec 23, 2020 •

Copy link
Copy Markdown
Member Author

@marcandre

marcandre commented Dec 23, 2020 •

Copy link
Copy Markdown
Member Author

Note that example with [:foo] is also faster, because Array#hash calls rb_hash on the Symbol, which also benefits from this optimization.
I've updated the benchmark to show timing for [[[]]]. That case does not benefit from this optimization but shows no big slowdown (unsurprisingly).

Comment thread include/ruby/internal/eval.h Outdated
Comment thread hash.c Outdated
Comment thread vm_eval.c Outdated
Comment thread vm_eval.c Outdated
Comment thread vm_eval.c Outdated
Comment thread vm_eval.c Outdated
This avoids recursive checks when the `hash` method of an object
isn't specialized.
@marcandre

marcandre commented Dec 24, 2020 •

Copy link
Copy Markdown
Member Author

@nurse
nurse merged commit db2ebbd into ruby:master Dec 24, 2020
@marcandre
marcandre deleted the hash_optimize branch December 27, 2020 16:22
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.

4 participants