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

EVM optimizations #2405

Merged
merged 3 commits into from
Dec 2, 2022
Merged

EVM optimizations #2405

merged 3 commits into from
Dec 2, 2022

Conversation

jochem-brouwer
Copy link
Member

This PR is aimed towards optimizing EVM. In particular, see: NomicFoundation/hardhat#3316 (comment)

When updating the EVM using chunk-sized extensions (so do not extend it with 32 bytes each time, but instead of containers of 8192 / 8 kb), MSTORE gets about 8 times faster (based upon above problem ^). It also almost halves the runtime of aboves' problem.

Still WIP because I might want to introduce more optimizations (plus this might cause a bunch of test errors).

@jochem-brouwer jochem-brouwer added PR state: WIP type: performance type: test all hardforks This special label enables VM state and blockchain tests for all hardforks on the respective PR. package: evm labels Nov 4, 2022
@codecov
Copy link

codecov bot commented Nov 4, 2022

Codecov Report

Merging #2405 (bb10347) into master (dc4cd91) will increase coverage by 0.02%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 89.51% <ø> (ø)
blockchain 90.03% <ø> (ø)
client 87.49% <ø> (+0.02%) ⬆️
common 98.16% <ø> (ø)
devp2p 91.70% <ø> (+0.10%) ⬆️
ethash ∅ <ø> (∅)
rlp ∅ <ø> (∅)
statemanager 89.61% <ø> (ø)
trie 90.36% <ø> (ø)
tx 97.80% <ø> (ø)
util 84.59% <ø> (ø)
vm 85.67% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

this._store = Buffer.concat([
this._store,
Buffer.alloc(Math.ceil(sizeDiff / CONTAINER_SIZE) * CONTAINER_SIZE),
])
Copy link
Member

Choose a reason for hiding this comment

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

Ok, just did a quick search ._store.length for the EVM to see if there are any external accesses to memory length where we would have side effects, but this seems not to be the case (apart from some memory-internal tests which can eventually be adopted if needed). 🙂

So this seems like a really clever solution to reduce the buffer allocations drastically along memory extensions! 👍

(still am a bit cautious and wonder though if this might have some side effect(s) somewhere? 🤔

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 agree that we should very carefully examine this. (I also did the same search as you did since I was afraid that there indeed might be external reads to it)

@axic
Copy link
Member

axic commented Nov 24, 2022

@jochem-brouwer for speed benchmarks you could try to plug in https://github.com/ipsilon/evm-benchmarks (it uses the general state tests format). If you do please let us know the results (or just tag me in the issue/PR).

@jochem-brouwer jochem-brouwer marked this pull request as ready for review November 30, 2022 18:19
Copy link
Contributor

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

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

LGTM!

@acolytec3 acolytec3 merged commit 4549045 into master Dec 2, 2022
@gitpoap-bot
Copy link

gitpoap-bot bot commented Dec 2, 2022

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2022 EthereumJS Contributor:

GitPOAP: 2022 EthereumJS Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

@acolytec3 acolytec3 mentioned this pull request Dec 15, 2022
1 task
@holgerd77 holgerd77 deleted the optimize-evm branch March 2, 2023 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: evm PR state: needs review type: performance type: test all hardforks This special label enables VM state and blockchain tests for all hardforks on the respective PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants