balancer / balancer-v3-monorepo

GNU General Public License v3.0
37 stars 10 forks source link

Minimize storage reads in WeightedPool::computeBalance #803

Closed gerrrg closed 1 month ago

gerrrg commented 1 month ago

Description

Currently, calling computeBalance() can perform (at most) 8 storage reads since it's calling _getNormalizedWeights() and then taking the ith index. Instead, we can directly query _getNormalizedWeight(i) and just perform a single storage read for the weight we want.

Type of change

Checklist:

Issue Resolution

EndymionJkb commented 1 month ago

Hmmm! Good catch; certainly seems like this should work. I don't believe we ever call this, which is one reason we never noticed. Should have a test. (We would have found that in the coverage tests I suppose.)

gerrrg commented 1 month ago

Ah, yeah good point @jubeira about immutable reads vs normal storage reads. Still seems like a good thing to add in, just not as significant as I initially thoughts 🙂