-
Notifications
You must be signed in to change notification settings - Fork 879
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
Cache MessageDigests #1984
Cache MessageDigests #1984
Conversation
Fetching the hash from the java security providers is often longer than the hashing itself, so we should cache results from the providers in a reusable fashion. Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
This will eliminate ~10% of the time wasted in mainnet block processing. More time was spent fetching the hash algo then actually executing it. |
private static final Supplier<MessageDigest> KECCAK256_SUPPLIER = | ||
Suppliers.memoize(() -> messageDigest(KECCAK256_ALG)); | ||
private static final Supplier<MessageDigest> SHA256_SUPPLIER = | ||
Suppliers.memoize(() -> messageDigest(SHA256_ALG)); | ||
private static final Supplier<MessageDigest> RIPEMD160_SUPPLIER = | ||
Suppliers.memoize(() -> messageDigest(RIPEMD160_ALG)); | ||
private static final Supplier<MessageDigest> BLAKE2BF_SUPPLIER = | ||
Suppliers.memoize(() -> messageDigest(BLAKE2BF_ALG)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about just initializing these statically instead of using Suppliers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The security providers may not be properly set up when the class initializes.
For example, the blake2f provider is loaded via besu code on startup, and since the algorithms are loaded by string reference the code that adds blake2f to the providers is not guaranteed to have run since there is no class file dependency. And this is the wrong place to do that provider setup.
Fetching the hash from the java security providers is often longer than the hashing itself, so we should cache results from the providers in a reusable fashion. Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com> Signed-off-by: Richard Hart <richardhart92@gmail.com>
Fetching the hash from the java security providers is often longer than the hashing itself, so we should cache results from the providers in a reusable fashion. Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
Fetching the hash from the java security providers is often longer than
the hashing itself, so we should cache results from the providers in a
reusable fashion.
Signed-off-by: Danno Ferrin danno.ferrin@gmail.com
Changelog