-
Notifications
You must be signed in to change notification settings - Fork 3
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
Optimization: Small changes on many functions V3 (wip) #217
base: main
Are you sure you want to change the base?
Conversation
Ergs comparison results:
|
src/op_handlers/far_call.rs
Outdated
// Invalid | ||
_ => return Err(EraVmError::IncorrectBytecodeFormat), | ||
}; | ||
|
||
code_info_bytes[1] = 0; | ||
// let code_key = U256::from_big_endian(&code_info_bytes); |
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.
Delete this comment
let mut address = 0; | ||
for value in code.iter() { | ||
heap.store(address, *value); | ||
address += 32; | ||
} |
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.
Seeing it starts with address 0, maybe we can just assign code
to the new heap instead. This way we avoid all the copying and just move the whole vector.
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.
Good idea!
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 actually don't know if there is an easy way of doing that, since code
is of type Vec<U256>
but heap
is of type Vec<u8>
.
I'll keep the code as is, but if you happen to know how to do that transformation it could be a good optimization.
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 am not saying to make this change now, but something to consider for a future pr: we could easily retrieve the code as a Vec<u8>
by adding a new function to the Storage
trait that decommits and returns it in that format. The reason it's easy is that in the current zksync-era
storage, bytecodes are originally stored as Vec<u8>
, and we are actually converting them to Vec (see here).
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.
Yep, if we are able to modify that trait (we are not following any API), then thats totally an option.
let mut address = 0; | ||
for value in code.iter() { | ||
heap.store(address, *value); | ||
address += 32; | ||
} |
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 am not saying to make this change now, but something to consider for a future pr: we could easily retrieve the code as a Vec<u8>
by adding a new function to the Storage
trait that decommits and returns it in that format. The reason it's easy is that in the current zksync-era
storage, bytecodes are originally stored as Vec<u8>
, and we are actually converting them to Vec (see here).
Description
This PR improves vm performance by making small changes to many functions.
Results
The results vary across different benchmark suites, showing changes from no difference to a 12% enhancement. When we aggregate the average execution times of all benchmarks, we observe an overall improvement of approximately 3%.
Dependencies
Changes were made to
default_aa_code_hash
andevm_interpreter_code_hash
variable types underexecution.rs
which require a bump on underlyingzksync-era
repository dependency. Because of that, this PR should only be merged together withera_vm_small_changes_v2