Skip to content

Avoid an allocation in BigInteger.Parse("-2147483648") - #104666

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
kzrnm:BigIntegerSmall
Dec 4, 2024
Merged

Avoid an allocation in BigInteger.Parse("-2147483648")#104666
tannergooding merged 2 commits into
dotnet:mainfrom
kzrnm:BigIntegerSmall

Conversation

@kzrnm

Copy link
Copy Markdown
Contributor

Possibly related to #97589 (comment)

Before the change, this = s_bnMinInt; was unreachable.

Benchmark

[DisassemblyDiagnoser][GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByMethod)]publicclassParseSmall{[Params("-2147483648","-2147483647","2147483647","2147483648")]publicstringN;[Benchmark]publicBigIntegerParse()=>BigInteger.Parse(N);}

BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3810/23H2/2023Update/SunValley3)
13th Gen Intel Core i5-13500, 1 CPU, 20 logical and 14 physical cores
.NET SDK 9.0.100-preview.5.24307.3
[Host] : .NET 9.0.0 (9.0.24.30607), X64 RyuJIT AVX2
LongRun : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
Job=LongRun IterationCount=100 LaunchCount=3 WarmupCount=15 
MethodToolchainNMeanErrorStdDevMedianRatioRatioSDCode SizeGen0AllocatedAlloc Ratio
Parse\main\corerun.exe-214748364754.29 ns0.118 ns0.599 ns54.10 ns1.000.001,226 B--NA
Parse\pr\corerun.exe-214748364753.41 ns0.053 ns0.270 ns53.39 ns0.980.011,226 B--NA
Parse\main\corerun.exe-214748364858.50 ns0.144 ns0.740 ns58.67 ns1.000.001,226 B0.002532 B1.00
Parse\pr\corerun.exe-214748364855.90 ns0.067 ns0.346 ns55.84 ns0.960.021,226 B--0.00
Parse\main\corerun.exe214748364752.68 ns0.048 ns0.242 ns52.66 ns1.000.001,226 B--NA
Parse\pr\corerun.exe214748364752.39 ns0.070 ns0.358 ns52.32 ns0.990.011,226 B--NA
Parse\main\corerun.exe214748364858.38 ns0.187 ns0.954 ns58.12 ns1.000.001,226 B0.002532 B1.00
Parse\pr\corerun.exe214748364857.65 ns0.097 ns0.491 ns57.59 ns0.990.021,226 B0.002532 B1.00

@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Jul 10, 2024
@danmoseley

Copy link
Copy Markdown
Contributor

@tannergooding still OK to merge?

@tannergooding
tannergooding merged commit 11031c4 into dotnet:mainDec 4, 2024
eduardo-vp pushed a commit to eduardo-vp/runtime that referenced this pull request Dec 5, 2024
Co-authored-by: Dan Moseley <danmose@microsoft.com>
@kzrnm
kzrnm deleted the BigIntegerSmall branch December 5, 2024 15:00
mikelle-rogers pushed a commit to mikelle-rogers/runtime that referenced this pull request Dec 10, 2024
Co-authored-by: Dan Moseley <danmose@microsoft.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jan 5, 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.

3 participants

@kzrnm@danmoseley@tannergooding