Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Nov 23, 2021

Conversation

eiriktsarpalis
Copy link
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

ghost commented Nov 17, 2021

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: -

@eiriktsarpalis eiriktsarpalis added this to the 7.0.0 milestone Nov 17, 2021
@eiriktsarpalis eiriktsarpalis self-assigned this Nov 17, 2021
@eiriktsarpalis
Copy link
Member Author

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  
Method Job Toolchain Mean Error StdDev Median Min Max Ratio MannWhitney(5%) RatioSD Gen 0 Allocated
GetBoolean Job-FUQUAC main 2.8165 ns 0.1692 ns 0.1948 ns 2.8422 ns 2.5458 ns 3.1353 ns 1.00 Base 0.00 - -
GetBoolean Job-YDOZOU branch 0.8665 ns 0.0409 ns 0.0454 ns 0.8526 ns 0.7965 ns 0.9707 ns 0.31 Faster 0.03 - -
GetByte Job-FUQUAC main 5.4397 ns 0.1241 ns 0.1274 ns 5.3930 ns 5.2623 ns 5.6818 ns 1.00 Base 0.00 - -
GetByte Job-YDOZOU branch 5.1384 ns 0.3780 ns 0.4353 ns 4.9519 ns 4.7354 ns 6.1092 ns 0.94 Same 0.07 - -
GetSByte Job-FUQUAC main 7.1106 ns 0.1867 ns 0.2150 ns 7.1770 ns 6.8054 ns 7.4653 ns 1.00 Base 0.00 - -
GetSByte Job-YDOZOU branch 6.6925 ns 0.2650 ns 0.2836 ns 6.7588 ns 6.0942 ns 7.0082 ns 0.94 Same 0.06 - -
GetInt16 Job-FUQUAC main 6.4500 ns 0.3514 ns 0.4047 ns 6.3876 ns 6.0177 ns 7.4662 ns 1.00 Base 0.00 - -
GetInt16 Job-YDOZOU branch 5.7096 ns 0.2241 ns 0.2581 ns 5.6211 ns 5.4118 ns 6.1950 ns 0.89 Faster 0.07 - -
GetInt32 Job-FUQUAC main 8.4749 ns 1.4131 ns 1.6273 ns 8.0409 ns 6.3367 ns 11.1699 ns 1.00 Base 0.00 - -
GetInt32 Job-YDOZOU branch 5.4810 ns 0.0766 ns 0.0598 ns 5.4576 ns 5.4267 ns 5.6180 ns 0.61 Faster 0.11 - -
GetInt64 Job-FUQUAC main 9.0873 ns 1.5370 ns 1.7700 ns 9.4883 ns 5.8067 ns 11.4945 ns 1.00 Base 0.00 - -
GetInt64 Job-YDOZOU branch 5.4136 ns 0.2221 ns 0.2558 ns 5.2805 ns 5.2102 ns 6.0198 ns 0.62 Faster 0.14 - -
GetUInt16 Job-FUQUAC main 7.2822 ns 1.4723 ns 1.6955 ns 6.5766 ns 5.3467 ns 10.0580 ns 1.00 Base 0.00 - -
GetUInt16 Job-YDOZOU branch 4.8283 ns 0.2588 ns 0.2981 ns 4.6886 ns 4.5588 ns 5.6227 ns 0.69 Faster 0.15 - -
GetUInt32 Job-FUQUAC main 6.9889 ns 0.4547 ns 0.5054 ns 6.9788 ns 6.2473 ns 7.9228 ns 1.00 Base 0.00 - -
GetUInt32 Job-YDOZOU branch 4.5581 ns 0.0152 ns 0.0118 ns 4.5603 ns 4.5293 ns 4.5792 ns 0.67 Faster 0.05 - -
GetUInt64 Job-FUQUAC main 8.1725 ns 0.5490 ns 0.6322 ns 7.8606 ns 7.4725 ns 9.1323 ns 1.00 Base 0.00 - -
GetUInt64 Job-YDOZOU branch 5.7099 ns 0.2730 ns 0.3144 ns 5.5599 ns 5.3975 ns 6.4749 ns 0.70 Faster 0.06 - -
GetSingle Job-FUQUAC main 40.6009 ns 1.8373 ns 2.1158 ns 39.0748 ns 38.3017 ns 43.4433 ns 1.00 Base 0.00 - -
GetSingle Job-YDOZOU branch 39.1417 ns 1.7830 ns 2.0533 ns 37.9699 ns 37.1308 ns 42.4615 ns 0.97 Same 0.08 - -
GetDouble Job-FUQUAC main 40.8536 ns 1.6843 ns 1.9396 ns 40.4190 ns 38.5091 ns 45.3608 ns 1.00 Base 0.00 - -
GetDouble Job-YDOZOU branch 38.4226 ns 0.2483 ns 0.2073 ns 38.4396 ns 38.1850 ns 38.9144 ns 0.95 Same 0.04 - -
GetDecimal Job-FUQUAC main 35.7573 ns 0.4656 ns 0.3888 ns 35.6460 ns 35.4638 ns 36.6519 ns 1.00 Base 0.00 - -
GetDecimal Job-YDOZOU branch 39.0665 ns 2.2975 ns 2.6458 ns 39.2431 ns 35.6924 ns 44.4279 ns 1.10 Same 0.07 - -
GetDateTime Job-FUQUAC main 39.5818 ns 1.7527 ns 2.0185 ns 38.3751 ns 37.9946 ns 43.0891 ns 1.00 Base 0.00 - -
GetDateTime Job-YDOZOU branch 40.8488 ns 2.1625 ns 2.4904 ns 39.5203 ns 38.4485 ns 46.4520 ns 1.03 Same 0.08 - -
GetDateTimeOffset Job-FUQUAC main 53.4745 ns 1.0400 ns 1.1127 ns 53.0668 ns 52.5477 ns 56.1400 ns 1.00 Base 0.00 - -
GetDateTimeOffset Job-YDOZOU branch 53.3517 ns 2.0967 ns 2.3304 ns 52.1424 ns 51.3580 ns 57.4384 ns 0.99 Same 0.04 - -
GetGuid Job-FUQUAC main 54.9456 ns 5.9212 ns 6.8189 ns 52.4980 ns 48.8981 ns 74.4949 ns 1.00 Base 0.00 - -
GetGuid Job-YDOZOU branch 52.9854 ns 2.7597 ns 3.1781 ns 53.0834 ns 49.5474 ns 59.1831 ns 0.98 Same 0.12 - -
GetString Job-FUQUAC main 33.5958 ns 1.5457 ns 1.7180 ns 34.0031 ns 30.6914 ns 35.7685 ns 1.00 Base 0.00 0.0110 112 B
GetString Job-YDOZOU branch 30.0117 ns 0.1319 ns 0.1101 ns 29.9962 ns 29.8371 ns 30.2521 ns 0.89 Faster 0.05 0.0111 112 B

@eiriktsarpalis eiriktsarpalis force-pushed the throwhelper-improvements branch from aae0d90 to 791ec4e Compare November 23, 2021 09:55
Sign up for free to 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