Skip to content
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: fast push/pop/swap/dup #21193

Closed
wants to merge 3 commits into from

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Jun 8, 2020

WIP.

This PR breaks consensus theoretically, because if there's a push outside the range of the code, we just push a zero on the stack. In practice, that's fine, because execution will stop at that point anyway.

There's something odd happening. I'm not getting any test failures, but

[user@work go-ethereum]$ ./build/bin/evm  --bench --codefile snailtracer.hex run  1>/dev/null
EVM gas used:    2645349802
execution time:  803.879902ms
allocations:     1073482
allocated bytes: 178875253

The gas used is funky. I think it may be because the bench flag makes the execution reuse the same state, and does not reset it between runs. So if the bench is invoked several times, it can report different values.

Some synthetic benchmarks:

name           old time/op    new time/op    delta
SimpleLoop-6      157ms ± 2%     157ms ± 1%     ~     (p=0.436 n=9+9)
PushPopLoop-6     144ms ± 1%      75ms ± 2%  -47.70%  (p=0.000 n=9+10)
SwapDupLoop-6    57.0ms ± 1%    61.6ms ± 4%   +8.03%  (p=0.000 n=8+9)

name           old alloc/op   new alloc/op   delta
PushPopLoop-6    50.4kB ± 0%    50.1kB ± 0%   -0.59%  (p=0.000 n=10+8)
SwapDupLoop-6    52.1kB ± 0%    52.1kB ± 0%     ~     (p=0.066 n=10+10)

name           old allocs/op  new allocs/op  delta
PushPopLoop-6      74.7 ± 1%      72.0 ± 0%   -3.61%  (p=0.000 n=10+10)
SwapDupLoop-6      72.7 ± 1%      73.0 ± 0%     ~     (p=0.294 n=10+8)

@holiman
Copy link
Contributor Author

holiman commented Jun 8, 2020

Master:

[user@work go-ethereum]$ ./build/bin/evm-master -statdump --codefile snailtracer.hex run  1>/dev/null
EVM gas used:    305382972
execution time:  369.50483ms
allocations:     398320
allocated bytes: 71044280

This PR:

[user@work go-ethereum]$ ./build/bin/evm -statdump --codefile snailtracer.hex run  1>/dev/null
EVM gas used:    305382972
execution time:  327.825754ms
allocations:     398310
allocated bytes: 71040024

@holiman holiman changed the title Fixedbig optimizations core/vm: fast push/pop/swap/dup Jun 8, 2020
@holiman
Copy link
Contributor Author

holiman commented Jun 8, 2020

Update with go1.14.4. I ran them three times each, took the best time

[user@work go-ethereum]$  ./build/bin/evm-master -statdump --codefile snailtracer.hex run  1>/dev/null
EVM gas used:    305382972
execution time:  374.332693ms
allocations:     2353
allocated bytes: 57102856
[user@work go-ethereum]$  ./build/bin/evm-21193 -statdump --codefile snailtracer.hex run  1>/dev/null
EVM gas used:    305382972
execution time:  316.023492ms
allocations:     2330
allocated bytes: 57097896

@holiman holiman force-pushed the fixedbig_optimizations branch 2 times, most recently from ecd9c58 to 11f707f Compare June 10, 2020 09:08
@holiman
Copy link
Contributor Author

holiman commented Jun 10, 2020

Against non-uint256 master branch:

name           old time/op    new time/op    delta
SwapDupLoop-6    65.6ms ± 5%    58.0ms ± 5%  -11.60%  (p=0.000 n=10+10)

name           old alloc/op   new alloc/op   delta
SwapDupLoop-6    48.5kB ± 0%    42.5kB ± 0%  -12.36%  (p=0.000 n=9+10)

name           old allocs/op  new allocs/op  delta
SwapDupLoop-6      69.0 ± 0%      70.5 ± 1%   +2.17%  (p=0.000 n=9+10)
name           old time/op    new time/op    delta
PushPopLoop-6    80.5ms ± 7%    75.1ms ± 2%  -6.74%  (p=0.000 n=10+9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants