-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
.NET6 System.Text.Json source-generator appears slower than .NET5 when doing Deserialization #61501
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsDescriptionHello, I was taking a look at: https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/ and thought I'd give the new source-generator approach a try. However, to my confusion a comparison benchmark run against So of course I am wondering if that is meant to be the case, what am I missing here? I'd at least expect de-serialization to be the same speed, not slower. To reproduce this I put up 3 repos here, with a summary attached:
The results were generated by running Configuration
Regression?I don't think this is a regression per-se, or perhaps it is as de-serialization seems slower now? Data
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1288 (21H1/May2021Update)
Intel Core i5-8265U CPU 1.60GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.100
[Host] : .NET Core 3.1.20 (CoreCLR 4.700.21.47003, CoreFX 4.700.21.47101), X64 RyuJIT
DefaultJob : .NET Core 3.1.20 (CoreCLR 4.700.21.47003, CoreFX 4.700.21.47101), X64 RyuJIT
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1288 (21H1/May2021Update)
Intel Core i5-8265U CPU 1.60GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.100
[Host] : .NET 5.0.11 (5.0.1121.47308), X64 RyuJIT
DefaultJob : .NET 5.0.11 (5.0.1121.47308), X64 RyuJIT
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1288 (21H1/May2021Update)
Intel Core i5-8265U CPU 1.60GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.100
[Host] : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
DefaultJob : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
AnalysisSome test repos I created:
|
Hi @JPThorne, I made a few changes to your net6 benchmark so that it's more deterministic and runs in all considered TFMs so it's easier to compare. My results are slightly different: .NET Core 3.1
.NET 5
.NET 6
Note that the performance gains in sourcegen deserialization aren't as pronounced, but that is to be expected, fast-path deserialization has not been implemented yet (see #55043). |
Hi @eiriktsarpalis thanks so much for the quick feedback. And good idea on combining them all in one repo, much easier to compare. My local results are consistent with yours, in the combined repo. I was curious though if I could get my standalone net6.0 repo to test faster than the net5.0 one, and if I don't essentially define the Removing:
etc. as you did seems to make a difference. Thanks. |
Could you clarify? I removed it so that we could focus testing on the baseline. Do you have indication that the particular feature has regressed in 6? |
@eiriktsarpalis the reflection test is not using the camel-case policy, while the source-gen is however both share the same JSON which is case-sensitive and Pascal-cased. This means the source-gen deserialize test is artificially much faster since none of the properties matched up and set. If the reflection serializer is updated to use the camel-case policy then the deserialize test should be just as fast as the source-gen one (since there is no fast-path for source-gen + deserialize). |
I hadn't noticed that the sourcegen class contained custom configuration. I removed it in eiriktsarpalis/net6-json-test@70132dd which should provide an apples-to-apples comparison:
|
Description
Hello, I was taking a look at: https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/ and thought I'd give the new source-generator approach a try.
However, to my confusion a comparison benchmark run against
net5.0
appears to be faster on de-serialization than the same thing onnet6.0
. The serialization is definitely faster though (yay).So of course I am wondering if that is meant to be the case, what am I missing here? I'd at least expect de-serialization to be the same speed, not slower.
To reproduce this I put up 3 repos here, with a summary attached:
The results were generated by running
dotnet run -c Release
against each repo in turn. Any feedback would be much appreciated of course, not 100% sure this Issue is in the correct repo.Configuration
What OS version, and what distro if applicable?
Windows 10 Pro, 10.0.19043 Build 19043
What is the architecture (x64, x86, ARM, ARM64)?
x64
If relevant, what are the specs of the machine?
Processor Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz 1.80 GHz
Installed RAM 16,0 GB (15,8 GB usable)
System type 64-bit operating system, x64-based processor
Regression?
I don't think this is a regression per-se, or perhaps it is as de-serialization seems slower now?
Data
net3.1
net5.0
net6.0
Analysis
Some test repos I created:
The text was updated successfully, but these errors were encountered: