Closed tmpolaczyk closed 4 years ago
Because nn is constant. It reuses a variable to avoid increasing the stack size, just pretend that instead of test[0] you see sqrt_nn.
test[0]
sqrt_nn
The only affected method is _decomposeScalar, where the improvement is from 937567 average gas used to 73016 (12x).
Output of yarn gas-analysis:
yarn gas-analysis
Old:
········································|···························|·············|····························· | Methods · 20 gwei/gas · 213.25 usd/eth │ ··················|·····················|·············|·············|·············|··············|·············· | Contract · Method · Min · Max · Avg · # calls · usd (avg) │ ··················|·····················|·············|·············|·············|··············|·············· | EcGasHelper · _decomposeScalar · 653611 · 1078579 · 937567 · 134 · 4.00 │ ··················|·····················|·············|·············|·············|··············|··············
New:
········································|···························|·············|····························· | Methods · 20 gwei/gas · 212.91 usd/eth │ ··················|·····················|·············|·············|·············|··············|·············· | Contract · Method · Min · Max · Avg · # calls · usd (avg) │ ··················|·····················|·············|·············|·············|··············|·············· | EcGasHelper · _decomposeScalar · 65071 · 78215 · 73016 · 134 · 0.31 │ ··················|·····················|·············|·············|·············|··············|··············
I had a better idea, see #23
Because nn is constant. It reuses a variable to avoid increasing the stack size, just pretend that instead of
test[0]
you seesqrt_nn
.The only affected method is _decomposeScalar, where the improvement is from 937567 average gas used to 73016 (12x).
Output of
yarn gas-analysis
:Old:
New: