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

Digest is ~5x slower on Ruby 3.x then 2.x #35

Open
baseballlover723 opened this issue Dec 29, 2021 · 5 comments
Open

Digest is ~5x slower on Ruby 3.x then 2.x #35

baseballlover723 opened this issue Dec 29, 2021 · 5 comments

Comments

@baseballlover723
Copy link

Digest is ~5x slower for SHA1, SHA2, and SHA256 on Ruby 3.x compared to Ruby 2.x. See https://gist.github.com/morimori/1330095#gistcomment-3975819 for more details and the benchmark. Note that I tried benchmarking with Ruby 3.0.3 with both Digest 3.0.0 and 3.1.0, as well as Ruby 3.1.0 and still had the same performance. I suspect that it has to do with the extraction of Digest into its own gem.

@hsbt
Copy link
Member

hsbt commented Jan 5, 2022

@rhenium Can you look this?

This performance regression may be intentional. Should we migrate it to like OpenSSL::Digest::SHA256?

@baseballlover723
Copy link
Author

Heres a gist of what I was personally using to benchmark: https://gist.github.com/baseballlover723/c02a6f803ac4147585d183d0430b205e. It might be useful to you all.

@jeremyevans
Copy link

My guess would be you get Ruby 3 level of performance (significantly slower) on Ruby 2 if you pass the --with-bundled-md5 --with-bundled-sha1 --with-bundled-sha2 options when configuring. This is because the extracted digest library doesn't appear to use the openssl digest versions if they are available (which Ruby 2 did to improve performance). Compare the ruby 2.7 digest_conf.rb file to the one in this extracted gem, and the code to use the optimized openssl implementation is missing: https://github.com/ruby/ruby/blob/v2_7_5/ext/digest/digest_conf.rb#L66-L80

The only code I can see in the current digest repository that uses openssl is the gemspec: spec.metadata["msys2_mingw_dependencies"] = "openssl", which I'm guessing may be a mistake.

@rhenium
Copy link
Member

rhenium commented Jan 7, 2022

Yes, this is likely caused by ruby/ruby#3149.

The performance degradation is not deliberate but somewhat expected because it now uses the bundled C implementation instead of OpenSSL's optimized implementation.

@baseballlover723
Copy link
Author

So people who want the higher performance of the Ruby 2.x version on ruby 3.x should just switch from using digest to openssl to keep using the same implementation as the Ruby 2.x version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants