sputnikvm
sputnikvm copied to clipboard
Performance: no lazy_static or const fn
Right now as we build on stable Rust, const fn
is not available. Thus struct like Gas
are constructed on the fly (the config file only store a u64
). Performance can be improved if we utilize lazy_static
or const fn
, if the latter ever stabilize (https://github.com/rust-lang/rust/issues/24111).
Moved to https://github.com/ethereumproject/sputnikvm/wiki/Performance-Improvements due to #175.
lazy_static
deps is now used in the core sputnikvm crate.
@sorpaas So all these precompiled gas functions need to be utilized with lazy_static
right?
Actually originally this was related to all const variables here (https://github.com/ethereumproject/sputnikvm/blob/master/src/eval/cost.rs#L9). Because Gas
needs to be constructed on the fly and it's not free, it might be a performance issue. (See all the Into::into()
below.)
Still, however, I just realized that Gas
implements Copy
trait, so even if when it is lazy-static-ed it might still not help a lot. A constraint on the Ethereum blockchain is that Gas, although its theoretical max value is U256::max_value()
, it in practice cannot exceed usize::max_value()
. A better way to handle this is probably to make Gas
a type parameter in all VM structs. After that, track the initial provided gas, if that value exceeds usize::max_value()
, use usize
as the type parameter, otherwise, fallback to the full U256
(the conditional check does not need to be in the sputnikvm
library).
The type parameter of gas G
usually only needs Add + Mul + Sub + From<usize>
. In the calculation of memory cost, however, there needs to be a checked multiply which does not belong to a trait, so a custom trait might need to be created for that.
Oops sorry I probably should be more careful when labeling an issue as "good first issue".