-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
core/vm: speed up push and interpreter loop #30662
Merged
Merged
Conversation
This file contains 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
Btw if we want this, we can also remove |
holiman
force-pushed
the
speedy_interpreter_loop
branch
from
October 23, 2024 11:42
63d2422
to
8c582ab
Compare
Added a benchmark
|
jwasinger
reviewed
Oct 23, 2024
|
||
// Missing bytes: pushByteSize - len(pushData) | ||
if missing := pushByteSize - (end - start); missing > 0 { |
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.
Even if we could remove this if
from the hot-loop and adjust the tracers correspondingly, it's (understandably) a micro optimization that doesn't bring measurable performance benefits:
│ bench_if_removed.txt │ bench_if_not_removed.txt │
│ sec/op │ sec/op vs base │
SimpleLoop/staticcall-identity-100M-12 162.9m ± 0% 160.7m ± 2% -1.35% (p=0.009 n=10)
SimpleLoop/call-identity-100M-12 183.9m ± 2% 180.8m ± 1% -1.64% (p=0.001 n=10)
SimpleLoop/loop-100M-12 182.0m ± 1% 182.0m ± 0% ~ (p=0.853 n=10)
SimpleLoop/loop2-100M-12 200.7m ± 0% 208.0m ± 5% +3.68% (p=0.000 n=10)
SimpleLoop/call-nonexist-100M-12 496.8m ± 2% 508.8m ± 9% +2.41% (p=0.011 n=10)
SimpleLoop/call-EOA-100M-12 142.3m ± 0% 141.1m ± 5% ~ (p=0.143 n=10)
SimpleLoop/call-reverting-100M-12 323.7m ± 0% 324.9m ± 1% ~ (p=0.123 n=10)
geomean 220.1m 220.9m +0.37%
s1na
reviewed
Oct 24, 2024
s1na
reviewed
Oct 24, 2024
Co-authored-by: Sina M <1591639+s1na@users.noreply.github.com>
holiman
added a commit
that referenced
this pull request
Nov 19, 2024
Looking at the cpu profile of a burntpix benchmark, I noticed that a lot of time was spent in gas-used, in the interpreter loop. It's an actual call (not inlined), which explicitly wants to be ignored by tracing ("tracing.GasChangeIgnored"), so it can be safely and simply inlined. The other change is in `pushX`. These also do a call to `common.RightPadBytes`. I replaced that by a doing a corresponding `Lsh` on the `u256` if needed. Note: it's needed only to make the stack output look right, for fuzzers. It technically doesn't matter what we put there: if code ends on a pushdata immediate, nothing will consume the stack element. We could just as well just ignore it, if we didn't care about fuzzers (which I do). Seems quite a lot faster on burntpix, according to my runs. This PR: ``` EVM gas used: 5642735088 execution time: 34.84609475s allocations: 915683 allocated bytes: 175334088 ``` ``` EVM gas used: 5642735088 execution time: 36.671958278s allocations: 915701 allocated bytes: 175340528 ``` Master ``` EVM gas used: 5642735088 execution time: 49.349209526s allocations: 915684 allocated bytes: 175333368 ``` ``` EVM gas used: 5642735088 execution time: 46.581006598s allocations: 915681 allocated bytes: 175330728 ``` --------- Co-authored-by: Sina M <1591639+s1na@users.noreply.github.com> Co-authored-by: Felix Lange <fjl@twurst.com>
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.
Looking at the cpu profile of a burntpix benchmark, I noticed that a lot of time was spent in gas-used, in the interpreter loop. It's an actual call (not inlined), which explicitly wants to be ignored by tracing ("tracing.GasChangeIgnored"), so it can be safely and simply inlined.
The other change is in
pushX
. These also do a call tocommon.RightPadBytes
. I replaced that by a doing a correspondingLsh
on theu256
if needed. Note: it's needed only to make the stack output look right, for fuzzers. It technically doesn't matter what we put there: if code ends on a pushdata immediate, nothing will consume the stack element. We could just as well just ignore it, if we didn't care about fuzzers (which I do).Seems quite a lot faster on burntpix, according to my runs.
This PR:
Master