perf(overflow): Speed up overflow checks for small integers#303
perf(overflow): Speed up overflow checks for small integers#303zeroshade merged 2 commits intoapache:mainfrom
Conversation
|
Sorry, I missed some hunks in my first commit. All fixed. |
|
It occurred to me today that this is better as two commits. The benchmarks are now committed, and one can try both implementations by switching between commits.
|
We can check the bounds of the arguments to avoid an int64 division. This adds benchmarks for the existing implementation, new functions, and tests, but does not change any behavior. Signed-off-by: Chris Bandy <bandy.chris@gmail.com>
These have proved faster in the aggregate and allow us to drop one dependency. Signed-off-by: Chris Bandy <bandy.chris@gmail.com>
|
Thanks for this @cbandy! I'll take a closer look at it this afternoon! |
zeroshade
left a comment
There was a problem hiding this comment.
Looks good to me @cbandy I'm seeing similar performance benefits when i test it myself locally. though I am curious about the small number of cases where it is slower. But I also want this in so I can start a release. The small number of cases that slow down don't seem to be worthwhile enough to be an issue so I'm going to merge this.
It would be awesome if you were able to figure out if those cases that were slower were just noise or indicative of something that might be an issue.
Thanks again for this!
Rationale for this change
We can check the bounds of the arguments to avoid an int64 division. The
MulandMul64functions perform better on the systems I tested.This is an older machine:
The following is inside a
docker.io/i386/ubuntucontainer on that same machine. I don't have any 32-bit hardware.What changes are included in this PR?
A new generic
Addfunction ininternal/utilsreturns the sum of any two integers and whether or not it overflowed.New
MulandMul64functions ininternal/utilsreturn the product of twointorint64, respectively, and whether or not it overflowed. These functions perform better on the systems I tested.Are these changes tested?
Yes.
Are there any user-facing changes?
No effect on the API. This drops one dependency.