Uh oh!
There was an error while loading. Please reload this page.
Optimize BigInteger.Parse - #97589
Conversation
ghost
commented
Jan 27, 2024
Tagging subscribers to this area: @dotnet/area-system-numerics Issue Details
BenchmarkusingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;usingSystem.Numerics;usingSystem.Runtime.InteropServices;BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);[DisassemblyDiagnoser]publicclassTests{[Params(1000,10000,100000,1000000)]publicintN;strings1,s2,s3;[GlobalSetup]publicvoidSetup(){s1="1"+newstring('0',N);s2="1"+newstring('0',N-1)+"1";s3=newstring('9',N-1);}[Benchmark]publicBigIntegerPowerOfTen()=>BigInteger.Parse(s1);[Benchmark(Baseline=true)]publicBigIntegerPowerOfTenPlusOne()=>BigInteger.Parse(s2);[Benchmark]publicBigIntegerPowerOfTenMinusOne()=>BigInteger.Parse(s3);}
|
0e0fa7f to
7cfc562Comparekzrnm
commented
Jan 29, 2024
I updated the benchmark target to the latest commit. |
tannergooding
commented
Jan 29, 2024
Thanks! Slowly getting through stuff here and just want to ensure no conflicts/accurate numbers/etc as they go through. |
tannergooding
commented
Jan 30, 2024
Looks like there are some related CI failures that need to get resolved. |
kzrnm
commented
Jan 31, 2024
Tests fail when |
894bbcc to
e2200c2Comparekzrnm
commented
Feb 1, 2024
I was able to reproduce the error with the following code. Number.s_naiveThreshold=0;BigInteger.Parse("99000000000"); |
e2200c2 to
96f4562Comparetannergooding
commented
Feb 1, 2024
@huoyaoyuan, if you have some time I'd appreciate if you could give this a once over as well, given you've also been touching/updating the parsing logic. I'd ideally like to get #95402 done first and I know there's another PR out, but you recently changed that one back to |
huoyaoyuan
commented
Feb 2, 2024
I've done the code update and measuring the performance. I'd expect to make it ready this weekend. |
dfde2c5 to
d69b10aCompare1da8f28 to
edc6a57Compare3daff74 to
9f5f44aCompare# Conflicts: # src/libraries/System.Runtime.Numerics/src/System/Numerics/BigIntegerCalculator.SquMul.cs # src/libraries/System.Runtime.Numerics/tests/BigInteger/multiply.cs
d785168 to
456bf8eComparef92dff4 to
29747f2Compareb3b8e56 to
f01a779Comparetannergooding
commented
Jul 1, 2024
@kzrnm, sorry for the delay on this. Could you share updated numbers, just so we can confirm nothing has regressed given all the other work that's been done? After that, I think we can get this merged. |
kzrnm
commented
Jul 2, 2024
@tannergooding I ran benchmarks on the latest branch.
|
@tannergooding Regressions: Mono related regressions:
|
tannergooding
commented
Jul 9, 2024
Just noting on the regressions above that many of them are for very small inputs, like Rather, we want to ensure that |
Optimize Multiplier
BigInteger.ParsetreatsThe leading
For example, the array represention of$10^{9\times2^8} = 10^{2304}$ has 957 items, of which the leading 288 items are 0.
Parse powers of ten
BigInteger.Parse("1" + new string('0', n))is too slow. It runs inThis is because trailing zeros are always calculated naively.
I fixed the behavior.
Benchmark