Skip to content

Conversation

@headius
Copy link
Member

@headius headius commented Jan 13, 2026

This experiment hooks up the hash4j library to String#hash. Any of the algorithms it provides can be used here by changing a line of code. This is proof-of-concept code used to compare the performance of the different algorithms.

Testing of the algorithms can use, among other things, the benchmark at https://bugs.ruby-lang.org/issues/21833 which compares different sizes of strings.

This experiment hooks up the hash4j library to String#hash. Any of
the algorithms it provides can be used here by changing a line of
code. This is proof-of-concept code used to compare the performance
of the different algorithms.

Testing of the algorithms can use, among other things, the
benchmark at https://bugs.ruby-lang.org/issues/21833 which compares
different sizes of strings.
@headius headius added this to the JRuby 10.1.0.0 milestone Jan 13, 2026
@headius
Copy link
Member Author

headius commented Jan 13, 2026

An example comparison using rapidhash3 versus the Ruby 4.0.0 release.

Before (JRuby using perlhash):

Comparison:
                     tiny_strings
          jruby-head:    932733.1 i/s 
          ruby-4.0.0:    391861.1 i/s - 2.38x  slower

                    small_strings
          jruby-head:    795430.8 i/s 
          ruby-4.0.0:    395953.0 i/s - 2.01x  slower

                   medium_strings
          jruby-head:    502150.9 i/s 
          ruby-4.0.0:    383490.9 i/s - 1.31x  slower

                    large_strings
          ruby-4.0.0:    186680.3 i/s 
          jruby-head:     46827.9 i/s - 3.99x  slower

                     huge_strings
          ruby-4.0.0:       855.1 i/s 
          jruby-head:       130.0 i/s - 6.58x  slower

After (JRuby using rapidhash3):

Comparison:
                     tiny_strings
          jruby-head:    819299.3 i/s 
          ruby-4.0.0:    390872.0 i/s - 2.10x  slower

                    small_strings
          jruby-head:    832171.2 i/s 
          ruby-4.0.0:    393664.5 i/s - 2.11x  slower

                   medium_strings
          jruby-head:    742292.6 i/s 
          ruby-4.0.0:    384353.1 i/s - 1.93x  slower

                    large_strings
          jruby-head:    248515.2 i/s 
          ruby-4.0.0:    186317.3 i/s - 1.33x  slower

                     huge_strings
          ruby-4.0.0:       851.9 i/s 
          jruby-head:       759.3 i/s - 1.12x  slower

I do not have a good explanation for the performance drop on the larger strings, but it's substantially reduced by using rapidhash3.

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.

1 participant