Repository navigation
Improve performance of BigInteger.Multiply - #1436
Conversation
|
Hi @axelheer, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! TTYL, DNFBOT; |
|
@axelheer, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
|
@dotnet-bot test this please |
There was a problem hiding this comment.
I know it's an internal type, but I think it would be better for code browsing if it was called BigIntegerCalculator, BigIntegerHelpers, BigIntegerMath, or something like that.
There was a problem hiding this comment.
Ok, I'll rename it.
|
BTW, the perf results are impressive. Thanks for doing this PR! I think it's a great example how the community members with domain expertise, like yourself, can make .NET better. I added some comments to the PR. The main one is that I wish the sources had more comments and some links to the algorithm description. |
There was a problem hiding this comment.
Do we need to be concerned about overflow here?
There was a problem hiding this comment.
Nope, I'll write some comments for explanation.
|
@hpshelton The cases you are pointing out regarding curly braces already conform to the style guidelines for this project. Sources: |
|
Thanks, @sharwell. Deleted all but one instance of the comment. |
There was a problem hiding this comment.
Per the style guidelines, I believe these are supposed to be _multiplyThreshold and _squareThreshold?
There was a problem hiding this comment.
It's a constant, so PascalCasing is correct (last item in the list). Perhaps this point should be closer to the other points related to naming.
There was a problem hiding this comment.
Darnit. Sorry. I'll add that to the list of things to fix on the wiki when I can figure out how to submit a PR for the wiki...
|
Thanks! I'll update the code accordingly. |
There was a problem hiding this comment.
Should I push an extra commit for this, or is it better to wait for further comments? I'm pretty new to this process...
There was a problem hiding this comment.
@axelheer I recommend installing the Visual Studio Spell Checker extension and making a pass through all the comments you added.
Most people wait for a period of time so reviewers add all their comments, but 12 hours is more than enough time to assume they've made the comments they want to for now. You can update it whenever you feel like it (or whenever you get away from the other things you work on). 😄
|
This looks good to me. Please squash the commits and I will merge this PR. |
To introduce performance tweaks for BigInteger's operations a new static class
BigCalcimplements those algorithms based on raw uint[] objects, partially switching even to pointer arithmetic to spare some index calculations. First of all a multiplication implementation is included, furthermore an optimized version for squaring.A basic performance comparison based on this code unveils the following results:
Multiply
Square
Note: the performance gain is not as big as expected based on my previous work (as mentioned within the issue), but I'd still call it significant. I actually had some difficulties executing a custom build of System.Runtime.Numerics though, since just dropping in the dll as described here does not work 'cause of some "type forwards". I finally managed to execute it using kre-coreclr-win-x64.1.0.0-beta3 and some hacks... 😳
#1307