Skip to content

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

Description

@baseballlover723

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.

Activity

  1. hsbt commented on Jan 5, 2022

    @hsbt
    Member

    @rhenium Can you look this?

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

  2. baseballlover723 commented on Jan 7, 2022

    @baseballlover723
    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.

  3. jeremyevans commented on Jan 7, 2022

    @jeremyevans

    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.

  4. rhenium commented on Jan 7, 2022

    @rhenium
    Member

    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.

  5. baseballlover723 commented on Jan 8, 2022

    @baseballlover723
    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.

  6. byroot commented on Apr 13, 2026

    @byroot
    Member

    Any chance we could solve this? It's quite a performance trap people keep falling into.

    Could we make openssl a dependency of digest?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions