Optimize keccak() for raw bytes inputs#326
Open
sanjaysudagani wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds a direct fast path in
eth_utils.keccak()for rawbytes,bytearray, andmemoryviewinputs when nohexstrortextargument is provided.Today those inputs always go through
to_bytes(), which means the common raw-bytes case still pays the conversion-argument validation and dispatch cost before hashing.What changed
eth_utils.crypto.keccakhexstr,text, ints, bools, and conflicting argument validationkeccak()tests, including a regression test that verifies rawbytesinput no longer callsto_bytes()Validation
pytest tests/core/crypto-utils/test_crypto.py tests/core/conversion-utils/test_conversions.py -qpre-commit run --files eth_utils/crypto.py tests/core/crypto-utils/test_crypto.pyBenchmark
On this machine, the common
keccak(bytes)path went from about2.90usper call to about2.33usper call for a 32-byte payload, reducing overhead over the raw backend from about29%to about4%.Closes #95