Skip to content

Split FormatBigInteger into smaller parts. - #112413

Closed
kzrnm wants to merge 1 commit into
dotnet:mainfrom
kzrnm:BigIntegerToBase1E9
Closed

Split FormatBigInteger into smaller parts.#112413
kzrnm wants to merge 1 commit into
dotnet:mainfrom
kzrnm:BigIntegerToBase1E9

Conversation

@kzrnm

Copy link
Copy Markdown
Contributor

Maybe fix#111708

After investigating the unexpected behavior in #111708, I concluded that JIT optimization is not functioning properly.

By splitting the part of FormatBigInteger that converts bits into base 1,000,000,000 into separate methods, I hope to improve JIT optimization.

This pull request conflicts with my pull request #112178, but I created this as I expect this PR to be backported to .NET 9.

Benchmark

In benchmarks using the released System.Runtime.Numerics.dll, it is about twice as slow compared to \main\corerun.exe.

Code
[MemoryDiagnoser(false)][HideColumns("Job","Error","StdDev","Median","RatioSD")]publicclassToStringTest{[Params([1<<15,1<<20,1<<21,])]publicintN;privatechar[]_dest=newchar[1_000_000];[GlobalSetup]publicvoidSetup(){bigInteger=System.Numerics.BigInteger.One<<N;}BigIntegerbigInteger;[Benchmark(Baseline=true)]publicvoidTryFormat()=>bigInteger.TryFormat(_dest,out_);}

BenchmarkDotNet v0.13.12, Windows 11 (10.0.26100.3037)
13th Gen Intel Core i5-13500, 1 CPU, 20 logical and 14 physical cores
.NET SDK 10.0.100-alpha.1.25077.2
[Host] : .NET 10.0.0 (10.0.25.7313), X64 RyuJIT AVX2
MediumRun : .NET 10.0.0 (42.42.42.42424), X64 RyuJIT AVX2
Job=MediumRun IterationCount=15 LaunchCount=2 WarmupCount=10 
MethodToolchainNMeanRatioAllocatedAlloc Ratio
TryFormat\main\corerun.exe32768985.8 μs1.00-NA
TryFormat\pr\corerun.exe32768984.6 μs1.00-NA
TryFormat\main\corerun.exe10485761,008,261.6 μs1.00-NA
TryFormat\pr\corerun.exe1048576862,085.5 μs0.86-NA
TryFormat\main\corerun.exe20971523,957,211.1 μs1.00-NA
TryFormat\pr\corerun.exe20971523,518,594.2 μs0.89-NA

@kzrnm

Copy link
Copy Markdown
ContributorAuthor

It seems that this might not be the appropriate change.

@kzrnmkzrnm closed this Feb 27, 2025
@kzrnm
kzrnm deleted the BigIntegerToBase1E9 branch March 7, 2025 01:30
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Apr 6, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Numericscommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Perf] BigInteger formatting performance regression in .NET 9

1 participant

@kzrnm