Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66360ad

Browse files
authored
Revert "Update JSON platform benchmarks to use JSON source generator (#1683)" (#1688)
This reverts commit bf3490f.
1 parent bf3490f commit 66360ad

File tree

6 files changed

+8
-74
lines changed

6 files changed

+8
-74
lines changed

src/BenchmarksApps/Kestrel/PlatformBenchmarks/BenchmarkApplication.Caching.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ public partial class BenchmarkApplication
1010
{
1111
private async Task Caching(PipeWriter pipeWriter, int count)
1212
{
13-
#if NET6_0_OR_GREATER
14-
OutputMultipleQueries(pipeWriter, await RawDb.LoadCachedQueries(count), SerializerContext.CachedWorldArray);
15-
#else
1613
OutputMultipleQueries(pipeWriter, await RawDb.LoadCachedQueries(count));
17-
#endif
1814
}
1915
}
2016
}
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Buffers;
56
using System.Text.Json;
67

78
namespace PlatformBenchmarks
89
{
910
public partial class BenchmarkApplication
1011
{
11-
private readonly static uint _jsonPayloadSize = (uint)JsonSerializer.SerializeToUtf8Bytes(
12-
new JsonMessage { message = "Hello, World!" },
13-
#if NET6_0_OR_GREATER
14-
SerializerContext.JsonMessage
15-
#else
16-
SerializerOptions
17-
#endif
18-
).Length;
12+
private readonly static uint _jsonPayloadSize = (uint)JsonSerializer.SerializeToUtf8Bytes(new JsonMessage { message = "Hello, World!" }, SerializerOptions).Length;
1913

2014
private readonly static AsciiString _jsonPreamble =
2115
_http11OK +
@@ -36,15 +30,7 @@ private static void Json(ref BufferWriter<WriterAdapter> writer, IBufferWriter<b
3630
utf8JsonWriter.Reset(bodyWriter);
3731

3832
// Body
39-
JsonSerializer.Serialize(
40-
utf8JsonWriter,
41-
new JsonMessage { message = "Hello, World!" },
42-
#if NET6_0_OR_GREATER
43-
SerializerContext.JsonMessage
44-
#else
45-
SerializerOptions
46-
#endif
47-
);
33+
JsonSerializer.Serialize<JsonMessage>(utf8JsonWriter, new JsonMessage { message = "Hello, World!" }, SerializerOptions);
4834
}
4935
}
5036
}

src/BenchmarksApps/Kestrel/PlatformBenchmarks/BenchmarkApplication.MultipleQueries.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,17 @@
44
using System.IO.Pipelines;
55
using System.Text.Json;
66
using System.Threading.Tasks;
7-
#if NET6_0_OR_GREATER
8-
using System.Text.Json.Serialization.Metadata;
9-
#endif
107

118
namespace PlatformBenchmarks
129
{
1310
public partial class BenchmarkApplication
1411
{
1512
private async Task MultipleQueries(PipeWriter pipeWriter, int count)
1613
{
17-
#if NET6_0_OR_GREATER
18-
OutputMultipleQueries(pipeWriter, await RawDb.LoadMultipleQueriesRows(count), SerializerContext.WorldArray);
19-
#else
2014
OutputMultipleQueries(pipeWriter, await RawDb.LoadMultipleQueriesRows(count));
21-
#endif
2215
}
2316

24-
#if NET6_0_OR_GREATER
25-
private static void OutputMultipleQueries<TWord>(PipeWriter pipeWriter, TWord[] rows, JsonTypeInfo<TWord[]> jsonTypeInfo)
26-
#else
2717
private static void OutputMultipleQueries<TWord>(PipeWriter pipeWriter, TWord[] rows)
28-
#endif
2918
{
3019
var writer = GetWriter(pipeWriter, sizeHint: 160 * rows.Length); // in reality it's 152 for one
3120

@@ -43,15 +32,7 @@ private static void OutputMultipleQueries<TWord>(PipeWriter pipeWriter, TWord[]
4332
utf8JsonWriter.Reset(pipeWriter);
4433

4534
// Body
46-
JsonSerializer.Serialize(
47-
utf8JsonWriter,
48-
rows,
49-
#if NET6_0_OR_GREATER
50-
jsonTypeInfo
51-
#else
52-
SerializerOptions
53-
#endif
54-
);
35+
JsonSerializer.Serialize<TWord[]>(utf8JsonWriter, rows, SerializerOptions);
5536

5637
// Content-Length
5738
lengthWriter.WriteNumeric((uint)utf8JsonWriter.BytesCommitted);

src/BenchmarksApps/Kestrel/PlatformBenchmarks/BenchmarkApplication.SingleQuery.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,7 @@ private static void OutputSingleQuery(PipeWriter pipeWriter, World row)
3232
utf8JsonWriter.Reset(pipeWriter);
3333

3434
// Body
35-
JsonSerializer.Serialize(
36-
utf8JsonWriter,
37-
row,
38-
#if NET6_0_OR_GREATER
39-
SerializerContext.World
40-
#else
41-
SerializerOptions
42-
#endif
43-
);
35+
JsonSerializer.Serialize<World>(utf8JsonWriter, row, SerializerOptions);
4436

4537
// Content-Length
4638
lengthWriter.WriteNumeric((uint)utf8JsonWriter.BytesCommitted);

src/BenchmarksApps/Kestrel/PlatformBenchmarks/BenchmarkApplication.Updates.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,7 @@ private static void OutputUpdates(PipeWriter pipeWriter, World[] rows)
3232
utf8JsonWriter.Reset(pipeWriter);
3333

3434
// Body
35-
JsonSerializer.Serialize(
36-
utf8JsonWriter,
37-
rows,
38-
#if NET6_0_OR_GREATER
39-
SerializerContext.WorldArray
40-
#else
41-
SerializerOptions
42-
#endif
43-
);
35+
JsonSerializer.Serialize<World[]>(utf8JsonWriter, rows, SerializerOptions);
4436

4537
// Content-Length
4638
lengthWriter.WriteNumeric((uint)utf8JsonWriter.BytesCommitted);

src/BenchmarksApps/Kestrel/PlatformBenchmarks/BenchmarkApplication.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Buffers.Text;
66
using System.IO.Pipelines;
77
using System.Text.Json;
8-
using System.Text.Json.Serialization;
98
using System.Threading.Tasks;
109
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
1110

@@ -35,6 +34,8 @@ public partial class BenchmarkApplication
3534

3635
private readonly static AsciiString _plainTextBody = "Hello, World!";
3736

37+
private static readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions();
38+
3839
private readonly static AsciiString _fortunesTableStart = "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>";
3940
private readonly static AsciiString _fortunesRowStart = "<tr><td>";
4041
private readonly static AsciiString _fortunesColumn = "</td><td>";
@@ -49,20 +50,6 @@ public partial class BenchmarkApplication
4950
[ThreadStatic]
5051
private static Utf8JsonWriter t_writer;
5152

52-
#if NET6_0_OR_GREATER
53-
private static readonly JsonContext SerializerContext = JsonContext.Default;
54-
55-
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Serialization)]
56-
[JsonSerializable(typeof(JsonMessage))]
57-
[JsonSerializable(typeof(CachedWorld[]))]
58-
[JsonSerializable(typeof(World[]))]
59-
private partial class JsonContext : JsonSerializerContext
60-
{
61-
}
62-
#else
63-
private static readonly JsonSerializerOptions SerializerOptions = new();
64-
#endif
65-
6653
public static class Paths
6754
{
6855
public readonly static AsciiString Json = "/json";

0 commit comments

Comments
 (0)