uint256: optimize div-related functions by reducing bounds check#168
uint256: optimize div-related functions by reducing bounds check#168holiman merged 1 commit intoholiman:masterfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #168 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 1626 1628 +2
=========================================
+ Hits 1626 1628 +2 |
holiman
left a comment
There was a problem hiding this comment.
Whether it makes any positive improvement or not is a but unclear, I think, because the benchmarks are inherently a bit flaky.
But I'm fairly certain that it can't hurt, and probably a slight improvement, so why not.
Thanks!
|
Using godbolt(https://go.godbolt.org/z/4nGefdYrM), I do see the bounds check is moved outside the loop. And the loop is inside another loop, so this PR should help. If you benchmark using an idle computer (don't benchmark with background jobs running), you definitely would see an upto 7% boost, several If the percent number in I have another PR doing loop unrolling which combined with this PR could have an upto 17% boost for div-related functions. |
|
Should I add loop unrolling in this PR to make the performance boost more obvious, or in another PR? |
Let's do that in a separate PR. |
Since functions
addToandsubMulToare in a for loop insideudivremKnuth, reducing bounds check in them should result in an observable performance boost.len(y) > 0should be guaranteed by those respective non-zero checks for divisors insideDiv,Mod,AddMod, etc.Test
Benchmark