-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JsonSerializer.Serialize<T>(Utf8JsonWriter, T) regression in .NET 6 #56993
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsBenchmark: using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.IO;
using System.Text.Json;
[MemoryDiagnoser]
public class Program
{
public static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
private Data _data = new Data { Name = "Stephen", Address = "Here" };
private MemoryStream _stream = new MemoryStream();
private Utf8JsonWriter _writer;
[GlobalSetup]
public void Setup()
{
_writer = new Utf8JsonWriter(_stream);
}
[Benchmark(OperationsPerInvoke = 1000)]
public void Serialize()
{
for (int i = 0; i < 1000; i++)
{
_stream.Position = 0;
_writer.Reset();
JsonSerializer.Serialize(_writer, _data);
}
}
internal class Data
{
public string Name;
public string Address;
}
} On my machine, running this with:
with .NET 5.0.8 and .NET 6.0.0 (6.0.21.40103), I get these results:
For me at least, that 25% regression is very consistent.
|
I can repro this; this is a regression mostly from refactoring done in #53212. However, the sample POCO above: internal class Data
{
public string Name;
public string Address;
} only measures serializer overhead, since fields are not serialized by default. |
Please re-verify based on #57327. Thanks |
Benchmark:
On my machine, running this with:
with .NET 5.0.8 and .NET 6.0.0 (6.0.21.40103), I get these results:
For me at least, that 25% regression is very consistent.
The text was updated successfully, but these errors were encountered: