Add a fast path for hashing numerics and immediates#9102
Add a fast path for hashing numerics and immediates#9102headius merged 3 commits intojruby:10.1-devfrom
Conversation
3930eb9 to
3837ce6
Compare
|
This is basically done. Several core types that can't normally be extended have been set up to do "simple hashing", and the The following types implement SimpleHash:
Any types that used
To support randomized hashing, the seed has been promoted to classloader-global from runtime-global. Stable hashing can still be enabled globally, although it was not configurable on a per-runtime basis before. All runtimes in a given JVM will use the same randomized seed. This could be a larger concern, so I am not merging yet. |
See jruby#9086 This is an attempt to eliminate dynamic hash calls for all numeric and immediate values (nil, booleans). See jruby#9102 for more details on this implementation.
3837ce6 to
9beadae
Compare
|
A quick benchmark shows the benefit of this change: BEFORE: AFTER: This is very nearly as fast as CRuby with YJIT, but the Fixnum construction cost and other missing optimizations are likely to blame. Further improvements could be done here by making more core types be simple hashable if their |
|
A naive implementation of fast-path hashing for String: This improves performance of a string-based array hash benchmark many times and beats YJIT: BEFORE: AFTER: YJIT: (YJIT is not super relevant here... CRuby has similar optimizations in their core classes that we've simply never implemented.) |
|
The logic in CRuby that bypasses dynamic calls to https://github.com/ruby/ruby/blob/6014ed99680fd3beb013dd8564f81f6c2f2a9f34/hash.c#L170-L210 |
|
So it turns out CRuby doesn't dispatch to |
See jruby#9086 This is an attempt to eliminate dynamic hash calls for all numeric and immediate values (nil, booleans). See jruby#9102 for more details on this implementation.
CRuby appears to skip calling `hash` for Symbol and String in all cases, including subclasses of String that replace the `hash` method.
a68f6f1 to
b703382
Compare
See #9086
This is an attempt to eliminate dynamic hash calls for all numeric and immediate values (nil, booleans). Additional changes to support this: