Skip to content

[System.Text.Json] Move inline throw statements to ThrowHelper - #61746

Merged
eiriktsarpalis merged 5 commits into
dotnet:mainfrom
eiriktsarpalis:throwhelper-improvements
Nov 23, 2021
Merged

[System.Text.Json] Move inline throw statements to ThrowHelper#61746
eiriktsarpalis merged 5 commits into
dotnet:mainfrom
eiriktsarpalis:throwhelper-improvements

Conversation

@eiriktsarpalis

Copy link
Copy Markdown
Member

Replaces a number of occurrences of throw ThrowHelper.GetException(); statements found in System.Text.Json with ThrowHelper.ThrowException(); method calls.

While .NET 6 codegen around exception throwing appears to have improved, I'm still seeing modest performance improvements in microbenchmarks, particularly around the Utf8JsonReader.Get*() methods, which are relatively small methods that inline throw statements.

Fix#59378.

@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.

Issue Details

Replaces a number of occurrences of throw ThrowHelper.GetException(); statements found in System.Text.Json with ThrowHelper.ThrowException(); method calls.

While .NET 6 codegen around exception throwing appears to have improved, I'm still seeing modest performance improvements in microbenchmarks, particularly around the Utf8JsonReader.Get*() methods, which are relatively small methods that inline throw statements.

Fix #59378.

Author:eiriktsarpalis
Assignees:-
Labels:

area-System.Text.Json

Milestone:-

@eiriktsarpaliseiriktsarpalis added this to the 7.0.0 milestone Nov 17, 2021
@eiriktsarpaliseiriktsarpalis self-assigned this Nov 17, 2021
Comment threadsrc/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.cs Outdated
Comment threadsrc/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs Outdated
Comment threadsrc/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.cs Outdated
@eiriktsarpalis

Copy link
Copy Markdown
MemberAuthor

FWIW here are results comparing the Utf8JsonReader.Get* benchmarks:

BenchmarkDotNet=v0.13.1.1616-nightly, OS=Windows 10.0.22000
Intel Core i9-10900X CPU 3.70GHz, 1 CPU, 20 logical and 10 physical cores
.NET SDK=7.0.100-alpha.1.21566.20
[Host] : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
Job-FUQUAC : .NET 7.0.0 (42.42.42.42424), X64 RyuJIT
Job-YDOZOU : .NET 7.0.0 (42.42.42.42424), X64 RyuJIT
PowerPlanMode=00000000-0000-0000-0000-000000000000 Arguments=/p:DebugType=portable,-bl:benchmarkdotnet.binlog IterationTime=250.0000 ms MaxIterationCount=20 MinIterationCount=15 WarmupCount=1 
MethodJobToolchainMeanErrorStdDevMedianMinMaxRatioMannWhitney(5%)RatioSDGen 0Allocated
GetBooleanJob-FUQUACmain2.8165 ns0.1692 ns0.1948 ns2.8422 ns2.5458 ns3.1353 ns1.00Base0.00--
GetBooleanJob-YDOZOUbranch0.8665 ns0.0409 ns0.0454 ns0.8526 ns0.7965 ns0.9707 ns0.31Faster0.03--
GetByteJob-FUQUACmain5.4397 ns0.1241 ns0.1274 ns5.3930 ns5.2623 ns5.6818 ns1.00Base0.00--
GetByteJob-YDOZOUbranch5.1384 ns0.3780 ns0.4353 ns4.9519 ns4.7354 ns6.1092 ns0.94Same0.07--
GetSByteJob-FUQUACmain7.1106 ns0.1867 ns0.2150 ns7.1770 ns6.8054 ns7.4653 ns1.00Base0.00--
GetSByteJob-YDOZOUbranch6.6925 ns0.2650 ns0.2836 ns6.7588 ns6.0942 ns7.0082 ns0.94Same0.06--
GetInt16Job-FUQUACmain6.4500 ns0.3514 ns0.4047 ns6.3876 ns6.0177 ns7.4662 ns1.00Base0.00--
GetInt16Job-YDOZOUbranch5.7096 ns0.2241 ns0.2581 ns5.6211 ns5.4118 ns6.1950 ns0.89Faster0.07--
GetInt32Job-FUQUACmain8.4749 ns1.4131 ns1.6273 ns8.0409 ns6.3367 ns11.1699 ns1.00Base0.00--
GetInt32Job-YDOZOUbranch5.4810 ns0.0766 ns0.0598 ns5.4576 ns5.4267 ns5.6180 ns0.61Faster0.11--
GetInt64Job-FUQUACmain9.0873 ns1.5370 ns1.7700 ns9.4883 ns5.8067 ns11.4945 ns1.00Base0.00--
GetInt64Job-YDOZOUbranch5.4136 ns0.2221 ns0.2558 ns5.2805 ns5.2102 ns6.0198 ns0.62Faster0.14--
GetUInt16Job-FUQUACmain7.2822 ns1.4723 ns1.6955 ns6.5766 ns5.3467 ns10.0580 ns1.00Base0.00--
GetUInt16Job-YDOZOUbranch4.8283 ns0.2588 ns0.2981 ns4.6886 ns4.5588 ns5.6227 ns0.69Faster0.15--
GetUInt32Job-FUQUACmain6.9889 ns0.4547 ns0.5054 ns6.9788 ns6.2473 ns7.9228 ns1.00Base0.00--
GetUInt32Job-YDOZOUbranch4.5581 ns0.0152 ns0.0118 ns4.5603 ns4.5293 ns4.5792 ns0.67Faster0.05--
GetUInt64Job-FUQUACmain8.1725 ns0.5490 ns0.6322 ns7.8606 ns7.4725 ns9.1323 ns1.00Base0.00--
GetUInt64Job-YDOZOUbranch5.7099 ns0.2730 ns0.3144 ns5.5599 ns5.3975 ns6.4749 ns0.70Faster0.06--
GetSingleJob-FUQUACmain40.6009 ns1.8373 ns2.1158 ns39.0748 ns38.3017 ns43.4433 ns1.00Base0.00--
GetSingleJob-YDOZOUbranch39.1417 ns1.7830 ns2.0533 ns37.9699 ns37.1308 ns42.4615 ns0.97Same0.08--
GetDoubleJob-FUQUACmain40.8536 ns1.6843 ns1.9396 ns40.4190 ns38.5091 ns45.3608 ns1.00Base0.00--
GetDoubleJob-YDOZOUbranch38.4226 ns0.2483 ns0.2073 ns38.4396 ns38.1850 ns38.9144 ns0.95Same0.04--
GetDecimalJob-FUQUACmain35.7573 ns0.4656 ns0.3888 ns35.6460 ns35.4638 ns36.6519 ns1.00Base0.00--
GetDecimalJob-YDOZOUbranch39.0665 ns2.2975 ns2.6458 ns39.2431 ns35.6924 ns44.4279 ns1.10Same0.07--
GetDateTimeJob-FUQUACmain39.5818 ns1.7527 ns2.0185 ns38.3751 ns37.9946 ns43.0891 ns1.00Base0.00--
GetDateTimeJob-YDOZOUbranch40.8488 ns2.1625 ns2.4904 ns39.5203 ns38.4485 ns46.4520 ns1.03Same0.08--
GetDateTimeOffsetJob-FUQUACmain53.4745 ns1.0400 ns1.1127 ns53.0668 ns52.5477 ns56.1400 ns1.00Base0.00--
GetDateTimeOffsetJob-YDOZOUbranch53.3517 ns2.0967 ns2.3304 ns52.1424 ns51.3580 ns57.4384 ns0.99Same0.04--
GetGuidJob-FUQUACmain54.9456 ns5.9212 ns6.8189 ns52.4980 ns48.8981 ns74.4949 ns1.00Base0.00--
GetGuidJob-YDOZOUbranch52.9854 ns2.7597 ns3.1781 ns53.0834 ns49.5474 ns59.1831 ns0.98Same0.12--
GetStringJob-FUQUACmain33.5958 ns1.5457 ns1.7180 ns34.0031 ns30.6914 ns35.7685 ns1.00Base0.000.0110112 B
GetStringJob-YDOZOUbranch30.0117 ns0.1319 ns0.1101 ns29.9962 ns29.8371 ns30.2521 ns0.89Faster0.050.0111112 B

Comment threadsrc/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs Outdated
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move throw calls inside ThrowHelper.Get* methods

4 participants

@eiriktsarpalis@stephentoub@jkotas@steveharter