Skip to content

Conversation

@omerfirmak
Copy link
Member

@omerfirmak omerfirmak commented Jun 20, 2025

simple enough. benchmark of a dummy EVM loop shows ~%2 speed up on my machine.

@omerfirmak omerfirmak requested a review from rjl493456442 as a code owner June 20, 2025 11:46
stack = newstack() // local stack
callContext = &ScopeContext{
op OpCode // current opcode
jumpTable *JumpTable = in.table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why it's a pointer at all

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess to avoid 2KB copies on each interpreter creation.

@fjl
Copy link
Contributor

fjl commented Jun 20, 2025

Please post benchstat comparison.

@omerfirmak
Copy link
Member Author

omerfirmak commented Jun 20, 2025

goos: linux
goarch: amd64
pkg: github.com/ethereum/go-ethereum/core/vm
cpu: AMD Ryzen 7 5700U with Radeon Graphics         
        │   old.txt   │              new.txt               │
        │   sec/op    │   sec/op     vs base               │
Loop-16   193.9n ± 4%   184.3n ± 2%  -4.95% (p=0.000 n=10)

        │  old.txt   │            new.txt             │
        │    B/op    │    B/op     vs base            │
Loop-16   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

        │  old.txt   │            new.txt             │
        │ allocs/op  │ allocs/op   vs base            │
Loop-16   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

"op" here is a 100 gas worth of execution.

@MariusVanDerWijden MariusVanDerWijden self-assigned this Jun 26, 2025
@omerfirmak
Copy link
Member Author

apparently there is an already existing VM benchmark in the repo. Will remove the one added here.

goos: linux
goarch: amd64
pkg: github.com/ethereum/go-ethereum/core/vm/runtime
cpu: AMD Ryzen 7 5700U with Radeon Graphics         
                                       │   old.txt   │               new.txt               │
                                       │   sec/op    │   sec/op     vs base                │
SimpleLoop/staticcall-identity-100M-16   313.4m ± 4%   276.9m ± 9%  -11.64% (p=0.000 n=10)
SimpleLoop/call-identity-100M-16         365.4m ± 3%   334.7m ± 1%   -8.40% (p=0.000 n=10)
SimpleLoop/loop-100M-16                  395.6m ± 3%   292.7m ± 1%  -26.01% (p=0.000 n=10)
SimpleLoop/loop2-100M-16                 336.1m ± 7%   314.1m ± 0%   -6.54% (p=0.023 n=10)
SimpleLoop/call-nonexist-100M-16         712.9m ± 3%   656.9m ± 0%   -7.86% (p=0.000 n=10)
SimpleLoop/call-EOA-100M-16              287.3m ± 7%   269.8m ± 1%   -6.10% (p=0.000 n=10)
SimpleLoop/call-reverting-100M-16        557.5m ± 2%   539.5m ± 3%   -3.23% (p=0.001 n=10)
geomean                                  403.4m        362.0m       -10.26%

                                       │    old.txt    │               new.txt                │
                                       │     B/op      │     B/op      vs base                │
SimpleLoop/staticcall-identity-100M-16   67.95Mi ±  0%   67.95Mi ± 0%        ~ (p=0.441 n=10)
SimpleLoop/call-identity-100M-16         66.58Mi ±  0%   66.58Mi ± 0%        ~ (p=0.204 n=10)
SimpleLoop/loop-100M-16                  5.906Ki ±  4%   5.175Ki ± 2%  -12.38% (p=0.000 n=10)
SimpleLoop/loop2-100M-16                 5.359Ki ± 10%   5.273Ki ± 4%        ~ (p=0.585 n=10)
SimpleLoop/call-nonexist-100M-16         119.6Mi ±  0%   119.6Mi ± 0%        ~ (p=0.128 n=10)
SimpleLoop/call-EOA-100M-16              22.79Mi ±  0%   22.79Mi ± 0%        ~ (p=0.515 n=10)
SimpleLoop/call-reverting-100M-16        163.8Mi ±  0%   163.8Mi ± 0%   -0.00% (p=0.002 n=10)
geomean                                  4.826Mi         4.725Mi        -2.10%

                                       │   old.txt   │              new.txt               │
                                       │  allocs/op  │  allocs/op   vs base               │
SimpleLoop/staticcall-identity-100M-16   2.740M ± 0%   2.740M ± 0%       ~ (p=0.577 n=10)
SimpleLoop/call-identity-100M-16         2.685M ± 0%   2.685M ± 0%       ~ (p=0.837 n=10)
SimpleLoop/loop-100M-16                   42.00 ± 2%    40.50 ± 1%  -3.57% (p=0.001 n=10)
SimpleLoop/loop2-100M-16                  40.50 ± 4%    41.00 ± 2%       ~ (p=1.000 n=10)
SimpleLoop/call-nonexist-100M-16         2.985M ± 0%   2.985M ± 0%  -0.00% (p=0.044 n=10)
SimpleLoop/call-EOA-100M-16              746.3k ± 0%   746.3k ± 0%       ~ (p=0.139 n=10)
SimpleLoop/call-reverting-100M-16        2.858M ± 0%   2.858M ± 0%  -0.00% (p=0.001 n=10)
geomean                                  96.80k        96.47k       -0.34%

Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, pretty crazy that this has such a big impact in the benchmarks

@MariusVanDerWijden
Copy link
Member

Deployed on 07/08 for a sanity check

@MariusVanDerWijden
Copy link
Member

Screenshot_2025-07-01_18-19-53
Seems like it is pretty significant (~10% faster)

@will-2012
Copy link

Screenshot_2025-07-01_18-19-53 Seems like it is pretty significant (~10% faster)

It seems to be very helpful for performance improvement. Can you explain further whether this change will affect performance? I don't understand it clearly.

@will-2012
Copy link

Screenshot_2025-07-01_18-19-53 Seems like it is pretty significant (~10% faster)

It seems to be very helpful for performance improvement. Can you explain further whether this change will affect performance? I don't understand it clearly.

In our test, no obvious changes were observed~

@MariusVanDerWijden MariusVanDerWijden merged commit bdf47f4 into ethereum:master Jul 7, 2025
4 of 6 checks passed
@MariusVanDerWijden MariusVanDerWijden added this to the 1.16.2 milestone Jul 7, 2025
howjmay pushed a commit to iotaledger/go-ethereum that referenced this pull request Aug 27, 2025
Moves the jumptable nil check our of the interpreter loop.
Benchmarks show a 2-10% improvement.
gballet pushed a commit to gballet/go-ethereum that referenced this pull request Sep 11, 2025
Moves the jumptable nil check our of the interpreter loop.
Benchmarks show a 2-10% improvement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants