-
Notifications
You must be signed in to change notification settings - Fork 781
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: Memory Fix & Other Optimizations #2570
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0a1abc0
EVM: Rename evm debug logger to evm:evm (one for package, one for cla…
holgerd77 8ab8758
VM: Rename message checkpoint to state checkpoint in debug message (t…
holgerd77 348561e
EVM: CALL/CREATE debug exit msg differentiation
holgerd77 f2d046a
EVM: avoid buffer copy in memory read (performance)
holgerd77 b147be1
EVM: Rewrite runCall() checkpoint/revert conditional for readability/…
holgerd77 bc8bce8
EVM: Added EIP check for transient storage checkpointing
holgerd77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
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.
Had to explicitly check that this could not lead to unwanted writes:
slice
is a view point, so if you edit this buffer, you edit the "original" buffer tooloaded
is not written to in this contextreturnBuffer
isfill
ed, and this actually copies the value (so if you edit it, it does not change the original)So this is great :)
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.
This is half-great. Martin (Holst Swende) explicitly said, that one of the core things we are doing not optimal in our VM is that we copy things around, while we should use the original pointer to memory (the test in the performance test suite this PR/change here half-fixes was actually that there was huge call data created in the test and this is then copied over and over on each repeated call).
So we should rather make sure that we also remove this
loaded
copy over time and double check that there are just no writes happening. This will eventually/likely give another huge/significant speed bump if we do this right.Independent from the approval on this PR, since this only eliminates one unnecessary copy. So safe anyhow. 🙂
Will merge in.
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.
(updated the comment above for better readability)
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.
I think this is fine,
loaded
is not a copy, it is a view, so this should be a super fast operation.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.
Yeah, ok, but then latest the
returnBuffer
will copy this over, right?So this is what we should avoid. Will play around with this a bit over the next days. So normally there is is no reason anyhow why memory read should be manipulated, I will go a bit through the places and see what is happening where. Maybe we can also do/solve/tackle this by social (dev) consensus, and just name all variables which still (can) contain memory pointers in some special way, something like
callDataMemoryPointer
or whatever, so that everyone knows that these need to be handled with special care.And for this 0-filling, maybe we can do this later in the pipeline on the places where this is needed (can't completely remember, I think you implemented/added this at some point?).
Just first round ideas, but baseline would be that we need to get rid of this as Martin suggested. This is what he wrote (already over a year ago):
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.
Update: just did the test, these are the numbers of the performance tests when we remove this
returnBuffer
copy (this is not out of the box working yet though and needs subsequent fixes, tested on some mainnet blocks).So these are the new values:
And these are the old ones:
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.
Ah, you are absolutely right regarding this copying, I now see the point. I will give this a look soon also, this does not seem trivial but I also do not think it will be super complex either.