-
Notifications
You must be signed in to change notification settings - Fork 438
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
Fast Keccak cache (wait-free and lockless) #7336
Conversation
The run for comparing them https://github.com/NethermindEth/nethermind/actions/runs/10419906977 |
81e0fde
to
68aa509
Compare
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.
Someone else should also review since I added a lot of changes
Requires mano a mano comparison with |
Can be merged once proven with #7346 |
Two more runs to compare logs: |
Can it give false positive? Find some Keccak for input that will be wrong (it will be keccak of different input, but have same length and same |
No, it can't give a false positive. The original input is preserved and properly compared. We use a fat struct that is copied on the stack and then compare, so no dirty reads/writes can happen. The copy is done under the lock. |
This PR introduces Keccaks caching (see #7333 and related for other attempts) that is minimal in regards to locks, copying and memory overhead. This PR introduces a
KeccakCache
that128k
values12MB
of unmanaged memory allocated onceInterlocked.CompareExchange
to lockVolatile.Write
to unlockIt does not augments the
ValueKeccak
itself, allowing the callsite owner to decide, whether or not the value should go through cache. Call sites amended:StateTree
address->Keccak calculationsEVM
Instruction.Keccak256
executionStorageTree
uint256 -> Keccak cell address calculationsThere are several interesting methods used in this PR:
int
to thatvolatile
andInterlocked
can operate on it20
and32
that are compared without calling to the spanEntry
can be copied on the stack, so that the lock is released in a fast mannerChanges
KeccakCache
that allows to cache values of the Keccak.Types of changes
What types of changes does your code introduce?
Testing
Benchmarks
Synthetic
Single threaded, hammering the same value:
With master
Running this branch and master, side by side
Profiling mainnet
Saves on approx 40% of keccaks when running mainnet (88780 to 53664 approx ~40%)
Requires testing
If yes, did you write tests?
Notes on testing
Optional. Remove if not applicable.
Documentation
Requires documentation update
If yes, link the PR to the docs update or the issue with the details labeled
docs
. Remove if not applicable.Requires explanation in Release Notes
If yes, fill in the details here. Remove if not applicable.
Remarks
Optional. Remove if not applicable.