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

Populating JSON properties support #83669

Merged
merged 9 commits into from
Apr 25, 2023

Conversation

krwq
Copy link
Member

@krwq krwq commented Mar 20, 2023

Fixes: #78556

For all samples below following options are used (also added in this PR):

JsonSerializerOptions options = new()
{
  PreferredObjectCreationHandling = JsonObjectCreationHandling.Populate
};
  • support for deserializing properties without setters:
A obj = JsonSerializer.Deserialize<A>("""{"Foo": {"Value": 5}}""", options);
// previously there was no way to deserialize `Foo` since it didn't have a setter

class A
{
    public B Foo { get; } = new B();
}

class B
{
    public int Value { get; set; }
}
  • one consequence of that is also that collections can be pre-populated:
A obj = JsonSerializer.Deserialize<A>("""{"Elements": [4,5,6]}""", options);
// obj.Elements will contain numbers 1-6

class A
{
    public List<int> Elements { get; } = new List<int>() { 1, 2, 3 };
}

APIs added in this PR

namespace System.Text.Json.Serialization;

public enum JsonObjectCreationHandling
{
    Replace = 0,
    Populate = 1,
}

// NOTE: System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Interface
//           For Property/Field - Populate is enforced
//           For Class/Struct/Interface - Populate is applied to properties where applicable
[AttributeUsage(
  AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface,
  AllowMultiple = false)]
public sealed partial class JsonObjectCreationHandlingAttribute : System.Text.Json.Serialization.JsonAttribute
{
    public JsonObjectCreationHandlingAttribute(System.Text.Json.Serialization.JsonObjectCreationHandling handling) { }
    public System.Text.Json.Serialization.JsonObjectCreationHandling Handling { get { throw null; } }
}

namespace System.Text.Json.Serialization.Metadata;

public abstract partial class JsonPropertyInfo
{
    public JsonObjectCreationHandling? ObjectCreationHandling { get; set; }
}

public abstract partial class JsonTypeInfo
{
    public JsonObjectCreationHandling? PreferredPropertyObjectCreationHandling { get; set; }
}


namespace System.Text.Json;

public partial class JsonSerializerOptions
{
    public JsonObjectCreationHandling PreferredObjectCreationHandling { get; set; } /*= JsonObjectCreationHandling.Replace; */
}

I have some minor TODOs left related to tests which I plan to address separately:

  • more advanced functional tests (I've started on that in .Objects test file - last test case)
  • test: required read-only property non-parametrized populatable (if not present)

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned krwq Mar 20, 2023
@ghost
Copy link

ghost commented Mar 20, 2023

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

Issue Details

Fixes: #78556

I have some minor TODOs left related to tests which I plan to address to create issues for as part of this PR:

  • F# test cases
  • more advanced functional tests (I've started on that in .Objects test file - last test case)

Implements plumbing for populating objects (without root level APIs). This adds lots of end to end test cases for collections, dictionaries and objects. They all cycle between testing fields, number handling and various different knobs. There are also 2 test cases which test all possible metadata knobs with combination of property which can or cannot be populated.

All implementation detail specs are described in the main issue.

Author: krwq
Assignees: krwq
Labels:

area-System.Text.Json, new-api-needs-documentation

Milestone: -

@krwq
Copy link
Member Author

krwq commented Apr 11, 2023

Grep for Slower/Faster in the benchmarks results folder.
Benchmarks run with --statisticalTest 3%% --filter "*System.Text.Json.Serialization*" on my box (I think 10% error here seems reasonable, I don't have better way to run this, I've tried reruning several times and I get similar results each time).

Slower

Method Job Toolchain Mean Error StdDev Median Min Max Ratio MannWhitney(3%) RatioSD Gen0 Gen1 Gen2 Allocated Alloc Ratio
System.Text.Json.Serialization.Tests.ColdStartSerialization_SimpleStructWithProperties_-report-github.md:29: NewCustomizedOptions Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe 999.0 ns 23.28 ns 25.88 ns 995.5 ns 964.2 ns 1,064.2 ns 1.06 Slower 0.07 0.0520 0.0040 0.0040 378 B
System.Text.Json.Serialization.Tests.ColdStartSerialization_SimpleStructWithProperties_-report-github.md:35: NewCachedCustomConverter Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe 1,045.3 ns 14.43 ns 13.50 ns 1,044.8 ns 1,019.9 ns 1,069.3 ns 1.04 Slower 0.02 0.0729 0.0086 0.0043 490 B
System.Text.Json.Serialization.Tests.ReadJson_ArrayList_-report-github.md:17: DeserializeFromString Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 17.17 μs 0.191 μs 0.160 μs 17.15 μs 16.95 μs 17.52 μs 1.04 Slower 3.9286 0.5000 24.44 KB 1.00
System.Text.Json.Serialization.Tests.ReadJson_BinaryData_-report-github.md:26: DeserializeFromString Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 523.9 ns 1.80 ns 1.60 ns 523.9 ns 520.7 ns 526.5 ns 1.04 Slower 0.01 0.1700 1.05 KB 1.00
System.Text.Json.Serialization.Tests.ReadJson_ImmutableSortedDictionary_String, String__-report-github.md:23: DeserializeFromReader Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 63.25 μs 0.296 μs 0.277 μs 63.15 μs 62.98 μs 63.83 μs 1.04 Slower 6.1759 0.7411 38.27 KB 1.00
System.Text.Json.Serialization.Tests.ReadJson_ImmutableSortedDictionary_String, String__-report-github.md:35: DeserializeFromStream Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 62.27 μs 0.651 μs 0.577 μs 62.23 μs 61.67 μs 63.51 μs 1.04 Slower 6.0976 0.7622 38.34 KB 1.00
System.Text.Json.Serialization.Tests.ReadJson_IndexViewModel_-report-github.md:23: DeserializeFromReader Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 32.28 μs 5.530 μs 6.369 μs 28.52 μs 26.54 μs 45.38 μs 1.09 Slower 0.05 3.5730 0.4466 22.07 KB
System.Text.Json.Serialization.Tests.ReadJson_IndexViewModel_-report-github.md:38: DeserializeFromStream Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 21.18 μs 0.142 μs 0.126 μs 21.14 μs 21.01 μs 21.42 μs 1.04 Slower 0.01 3.5614 0.4240 22.14 KB
System.Text.Json.Serialization.Tests.ReadJson_Int32_-report-github.md:23: DeserializeFromReader Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 168.34 ns 5.426 ns 6.031 ns 167.54 ns 158.89 ns 182.23 ns 1.05 Slower 0.04 - - NA
System.Text.Json.Serialization.Tests.ReadJson_LargeStructWithProperties_-report-github.md:32: DeserializeFromReader Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 1,425.6 ns 10.53 ns 9.85 ns 1,425.8 ns 1,406.9 ns 1,440.5 ns 1.03 Slower 0.0285 200 B 1.00
System.Text.Json.Serialization.Tests.ReadJson_MyEventsListerViewModel_-report-github.md:20: DeserializeFromUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 228.0 μs 1.09 μs 0.97 μs 227.7 μs 226.7 μs 229.9 μs 1.04 Slower 11.8074 2.7248 76.96 KB 1.00
System.Text.Json.Serialization.Tests.ReadJson_MyEventsListerViewModel_-report-github.md:26: DeserializeFromString Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 231.9 μs 1.65 μs 1.46 μs 231.3 μs 230.4 μs 235.6 μs 1.04 Slower 12.1269 2.7985 76.96 KB 1.00
System.Text.Json.Serialization.Tests.ReadJson_MyEventsListerViewModel_-report-github.md:29: DeserializeFromUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 227.5 μs 1.76 μs 1.65 μs 227.5 μs 224.4 μs 231.0 μs 1.04 Slower 11.9485 2.7574 76.96 KB 1.00
System.Text.Json.Serialization.Tests.ReadJson_MyEventsListerViewModel_-report-github.md:38: DeserializeFromStream Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 264.7 μs 1.79 μs 1.59 μs 264.8 μs 262.0 μs 267.1 μs 1.04 Slower 12.5523 3.1381 77.99 KB 1.00
System.Text.Json.Serialization.Tests.ReadJson_Nullable_DateTimeOffset__-report-github.md:26: DeserializeFromString Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 153.3 ns 0.60 ns 0.56 ns 153.2 ns 152.44 ns 154.4 ns 1.04 Slower 0.01 - - NA
System.Text.Json.Serialization.Tests.ReadJson_Nullable_DateTimeOffset__-report-github.md:32: DeserializeFromReader Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 221.7 ns 4.74 ns 5.46 ns 223.5 ns 208.23 ns 226.2 ns 1.09 Slower 0.03 - - NA
System.Text.Json.Serialization.Tests.ReadJson_SimpleStructWithProperties_-report-github.md:26: DeserializeFromString Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 294.0 ns 1.60 ns 1.33 ns 294.2 ns 291.9 ns 295.8 ns 1.04 Slower 0.00 0.0094 64 B 1.00
System.Text.Json.Serialization.Tests.ReadJson_SimpleStructWithProperties_-report-github.md:35: DeserializeFromStream Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 494.2 ns 2.39 ns 2.12 ns 494.0 ns 490.3 ns 498.3 ns 1.07 Slower 0.01 0.0218 144 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_HashSet_String__-report-github.md:20: SerializeToUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 4.453 μs 0.0315 μs 0.0263 μs 4.445 μs 4.409 μs 4.488 μs 1.05 Slower 0.4728 - 3024 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_HashSet_String__-report-github.md:32: SerializeToUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 3.388 μs 0.0290 μs 0.0257 μs 3.379 μs 3.354 μs 3.437 μs 1.04 Slower 0.4735 - 2984 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_Int32_-report-github.md:26: SerializeObjectProperty Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 211.11 ns 0.981 ns 0.870 ns 210.94 ns 209.99 ns 212.87 ns 1.04 Slower 0.01 0.0076 48 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_LoginViewModel_-report-github.md:26: SerializeObjectProperty Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 467.1 ns 5.87 ns 5.49 ns 466.3 ns 457.5 ns 479.2 ns 1.07 Slower 0.01 0.0818 520 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_LoginViewModel_-report-github.md:32: SerializeToUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 224.8 ns 0.95 ns 0.84 ns 224.6 ns 223.6 ns 226.9 ns 1.15 Slower 0.02 0.0172 112 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_Nullable_DateTimeOffset__-report-github.md:20: SerializeToUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 167.35 ns 1.494 ns 1.398 ns 166.72 ns 165.55 ns 170.28 ns 1.04 Slower 0.01 0.0088 56 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_SimpleStructWithProperties_-report-github.md:29: SerializeToString Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 161.34 ns 0.900 ns 0.703 ns 161.43 ns 160.25 ns 162.19 ns 1.05 Slower 0.01 0.0112 72 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_SimpleStructWithProperties_-report-github.md:32: SerializeToUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 155.22 ns 1.507 ns 1.410 ns 155.36 ns 153.03 ns 158.29 ns 1.11 Slower 0.01 0.0074 48 B 1.00

Faster

Method Job Toolchain Mean Error StdDev Median Min Max Ratio MannWhitney(3%) RatioSD Gen0 Gen1 Gen2 Allocated Alloc Ratio
System.Text.Json.Serialization.Tests.ColdStartSerialization_SimpleStructWithProperties_-report-github.md:20: NewDefaultOptions Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe 876.4 ns 23.44 ns 26.05 ns 873.0 ns 835.3 ns 936.0 ns 0.91 Faster 0.07 0.0510 0.0036 0.0036 353 B
System.Text.Json.Serialization.Tests.ColdStartSerialization_SimpleStructWithProperties_-report-github.md:23: CachedJsonSerializerContext Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe 485.3 ns 6.25 ns 5.22 ns 485.2 ns 477.0 ns 497.7 ns 0.92 Faster 0.04 0.0207 - - 136 B
System.Text.Json.Serialization.Tests.ReadJson_Dictionary_String, String__-report-github.md:20: DeserializeFromUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 13.06 μs 0.055 μs 0.049 μs 13.05 μs 12.98 μs 13.14 μs 0.94 Faster 0.01 4.0975 0.4668 25.27 KB
System.Text.Json.Serialization.Tests.ReadJson_Hashtable_-report-github.md:35: DeserializeFromStream Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 28.35 μs 0.141 μs 0.125 μs 28.37 μs 28.14 μs 28.53 μs 0.95 Faster 0.01 6.2614 1.2523 38.44 KB
System.Text.Json.Serialization.Tests.ReadJson_IndexViewModel_-report-github.md:32: DeserializeFromReader Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 26.14 μs 0.405 μs 0.379 μs 26.11 μs 25.59 μs 26.90 μs 0.91 Faster 0.04 3.5124 0.4132 22.07 KB
System.Text.Json.Serialization.Tests.ReadJson_Int32_-report-github.md:26: DeserializeFromString Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 102.25 ns 0.410 ns 0.363 ns 102.28 ns 101.74 ns 102.99 ns 0.90 Faster 0.06 - - NA
System.Text.Json.Serialization.Tests.ReadJson_Nullable_DateTimeOffset__-report-github.md:17: DeserializeFromString Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 150.6 ns 1.10 ns 1.03 ns 150.2 ns 149.41 ns 152.9 ns 0.96 Faster 0.01 - - NA
System.Text.Json.Serialization.Tests.WriteJson_ArrayList_-report-github.md:44: SerializeToStream Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 5.488 μs 0.0730 μs 0.0682 μs 5.456 μs 5.415 μs 5.616 μs 0.96 Faster 0.01 0.0216 152 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_BinaryData_-report-github.md:44: SerializeToStream Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 320.6 ns 1.88 ns 1.67 ns 320.1 ns 318.9 ns 324.1 ns 0.91 Faster 0.03 0.0039 - 32 B
System.Text.Json.Serialization.Tests.WriteJson_ImmutableSortedDictionary_String, String__-report-github.md:44: SerializeToStream Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 6.581 μs 0.0559 μs 0.0523 μs 6.599 μs 6.510 μs 6.702 μs 0.94 Faster 0.02 - - 32 B
System.Text.Json.Serialization.Tests.WriteJson_Int32_-report-github.md:20: SerializeToUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 98.73 ns 0.515 ns 0.430 ns 98.60 ns 98.16 ns 99.74 ns 0.89 Faster 0.02 0.0049 32 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_Int32_-report-github.md:32: SerializeToUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 98.73 ns 0.404 ns 0.358 ns 98.75 ns 98.28 ns 99.45 ns 0.94 Faster 0.01 0.0049 32 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_Int32_-report-github.md:35: SerializeToWriter Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 39.08 ns 0.095 ns 0.074 ns 39.08 ns 38.98 ns 39.23 ns 0.96 Faster 0.00 - - NA
System.Text.Json.Serialization.Tests.WriteJson_Int32_-report-github.md:38: SerializeObjectProperty Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 204.52 ns 0.820 ns 0.727 ns 204.49 ns 203.55 ns 205.67 ns 0.90 Faster 0.01 0.0075 48 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_Int32_-report-github.md:44: SerializeToStream Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 139.20 ns 0.903 ns 0.800 ns 138.93 ns 138.36 ns 140.92 ns 0.94 Faster 0.00 0.0241 152 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_Location_-report-github.md:32: SerializeToUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 454.2 ns 3.14 ns 2.78 ns 453.9 ns 449.9 ns 458.9 ns 0.93 Faster 0.01 0.0364 232 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_LoginViewModel_-report-github.md:20: SerializeToUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 248.5 ns 1.34 ns 1.26 ns 248.7 ns 247.1 ns 251.3 ns 0.97 Faster 0.01 0.0174 112 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_Nullable_DateTimeOffset__-report-github.md:38: SerializeObjectProperty Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 262.33 ns 4.648 ns 4.347 ns 261.87 ns 256.40 ns 272.26 ns 0.96 Faster 0.02 0.0147 96 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_SimpleStructWithProperties_-report-github.md:20: SerializeToUtf8Bytes Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe Reflection 191.94 ns 0.495 ns 0.439 ns 191.78 ns 191.39 ns 193.00 ns 0.86 Faster 0.00 0.0124 80 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_SimpleStructWithProperties_-report-github.md:35: SerializeToWriter Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 79.93 ns 1.327 ns 1.241 ns 79.36 ns 78.72 ns 82.41 ns 0.90 Faster 0.06 - - NA
System.Text.Json.Serialization.Tests.WriteJson_SimpleStructWithProperties_-report-github.md:38: SerializeObjectProperty Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 334.82 ns 2.833 ns 2.366 ns 333.98 ns 331.48 ns 339.43 ns 0.91 Faster 0.01 0.0636 400 B 1.00
System.Text.Json.Serialization.Tests.WriteJson_SimpleStructWithProperties_-report-github.md:44: SerializeToStream Job-UVSXFN \runtime\artifacts\bin\testhost\net8.0-windows-Release-x64\shared\Microsoft.NETCore.App\8.0.0\corerun.exe SourceGen 185.67 ns 0.953 ns 0.891 ns 185.53 ns 184.09 ns 186.91 ns 0.94 Faster 0.01 0.0046 32 B 1.00

@krwq
Copy link
Member Author

krwq commented Apr 11, 2023

/benchmark microbenchmarks aspnet-perf-win libs --variable filter="System.Text.Json.Tests*"

@pr-benchmarks
Copy link

pr-benchmarks bot commented Apr 11, 2023

Benchmark started for microbenchmarks on aspnet-perf-win with libs and arguments --variable filter="System.Text.Json.Tests*". Logs: link

…extend unit testing for the new metadata APIs.
Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Great work overall 👍

@eiriktsarpalis eiriktsarpalis merged commit ed9fbe3 into dotnet:main Apr 25, 2023
@eiriktsarpalis eiriktsarpalis deleted the populate-object-maybe-p3 branch April 25, 2023 16:26
@eiriktsarpalis eiriktsarpalis restored the populate-object-maybe-p3 branch April 25, 2023 16:26
@cincuranet
Copy link
Contributor

Although not a big and clear regression, could you look at regressions in System.Text.Json.Tests.Perf_Reader in dotnet/perf-autofiling-issues#17216? Might be related.

@eiriktsarpalis
Copy link
Member

The Perf_Reader benchmarks measure performance of Utf8JsonReader, which is lower level than the serialization layer that this PR modifies.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 3, 2023
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.

Support modifying already initialized properties and fields when deserializing JSON
4 participants