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?