-
Notifications
You must be signed in to change notification settings - Fork 595
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
High Overhead - MessageDigest #3157
Comments
I wonder if we can just cheat by having an Cheating because:
|
Isn't that effectively what keypool does? What's the advantage of rolling our own here? |
Putting aside the issue of keypool specifically, doing anything more than this has two issues:
|
I would think 2 would be needed regardless, as an |
Hence, cheat (1) :) I say just put it in the |
My bigger take-away here is that we are stretching the limits of what |
I would probably agree with this. Either a separate library or just having it in CE would make sense to me. |
I don't think fs2 should have a dependency on keypool. If the improvements in Java 17 address all or most of the issue, then I think we should keep things as-is. |
Bringing this up per a discord conversation with @armanbilge , @djspiewak and @mpilquist .
I was looking to use hashing functionality in FS2 as I believe it is one of the (if not the) only Scala Native / Scala.js compliant abstraction for hashing.
However, it seems that the definition will call
MessageDigest.getInstance
on every invocation of the Pipe. This has a very high overhead. References:https://cl4es.github.io/2021/01/04/Investigating-MD5-Overheads.html
svroonland/zio-kinesis#732
https://bugs.openjdk.org/browse/JDK-8259065 (slight improvement via caching in Java 17)
For me, this was problematic, as I was going to be calling that pipe several times (e.g. hash this record). It looks like Java 17 is going to start caching default constructors, but many users are likely still on older java versions, and using this would incur a pretty high cost.
Something we could do is leverage https://github.com/typelevel/keypool to create our own cache of MessageDigest instances. This could substantially lower the overhead of these offerings.
Important to note that MessageDigest must have its
reset()
function invoked before it is re-used.The text was updated successfully, but these errors were encountered: