0

Here are two pieces of code:

fn f() {
    (0..1000).for_each(|_| {
        let x = <X<T>>::get();

        g(x);
    });
    
}
fn f() {
    let x = <X<T>>::get();

    (0..1000).for_each(|_| { g(x); });
}

Once data is read from storage, it will exist in the cache. But how does its performance compare?

Is it necessary to optimize the first case everywhere?

For instance, the block number is frequently used in various functions. Should I pass it along the function chain or retrieve it from the storage cache in each function?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.