Skip to content

Commit 35691d5

Browse files
authored
Don't box struct writer in Json (#1524)
1 parent e070686 commit 35691d5

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Buffers;
56
using System.Text.Json;
67

78
namespace PlatformBenchmarks
@@ -19,7 +20,7 @@ public partial class BenchmarkApplication
1920
[ThreadStatic]
2021
private static Utf8JsonWriter t_writer;
2122

22-
private static void Json(ref BufferWriter<WriterAdapter> writer)
23+
private static void Json(ref BufferWriter<WriterAdapter> writer, IBufferWriter<byte> bodyWriter)
2324
{
2425
writer.Write(_jsonPreamble);
2526

@@ -28,8 +29,8 @@ private static void Json(ref BufferWriter<WriterAdapter> writer)
2829

2930
writer.Commit();
3031

31-
Utf8JsonWriter utf8JsonWriter = t_writer ??= new Utf8JsonWriter(writer.Output, new JsonWriterOptions { SkipValidation = true });
32-
utf8JsonWriter.Reset(writer.Output);
32+
Utf8JsonWriter utf8JsonWriter = t_writer ??= new Utf8JsonWriter(bodyWriter, new JsonWriterOptions { SkipValidation = true });
33+
utf8JsonWriter.Reset(bodyWriter);
3334

3435
// Body
3536
JsonSerializer.Serialize<JsonMessage>(utf8JsonWriter, new JsonMessage { message = "Hello, World!" }, SerializerOptions);

src/BenchmarksApps/Kestrel/PlatformBenchmarks/BenchmarkApplication.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private void ProcessRequest(ref BufferWriter<WriterAdapter> writer)
160160
}
161161
else if (_requestType == RequestType.Json)
162162
{
163-
Json(ref writer);
163+
Json(ref writer, Writer);
164164
}
165165
else
166166
{

0 commit comments

Comments
 (0)