Skip to content

Consider caching Utf8JsonWriter and PooledByteBufferWriter on a thread static in JsonSerializer.Serialize #69889

@davidfowl

Description

@davidfowl

Description

Looking into the allocation profile for our JSON tech empower benchmark, the allocation overhead for the JsonSerializer itself

Configuration

Run this crank command.

crank --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/json.benchmarks.yml --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/build/azure.profile.yml --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/build/ci.profile.yml --scenario https --profile intel-lin-app --profile intel-load2-load --application.framework net7.0 --application.collectDependencies true --application.options.collectCounters true --application.aspNetCoreVersion 7.0.0-preview.6.22275.2 --application.runtimeVersion 7.0.0-preview.6.22276.3 --application.sdkVersion 7.0.100-preview.6.22275.1  --application.dotnetTrace true --application.dotnetTraceProviders gc-verbose

This will run the JsonHttps benchmark and it'll spit out an allocation profile that you can view in perfview (alloc tick events).

Regression?

No it's not

Data

Name                                         Exc %           Exc Exc CtInc %             Inc Inc CtFoldFold Ct                             When      First       Last
Type System.Text.Json.Utf8JsonWriter          73.52,195,098,368.000 20,668 73.52,195,098,368.000 20,668   0      0 79oEEEDEEDEEEEEDCEEEFEDFEDEEDEED 21,998.809 52,258.721
Type System.Text.Json.PooledByteBufferWriter 16.5   493,749,376  4,649 16.5     493,749,376  4,649   0      0 112o3332333332333333233333333333 22,031.344 52,235.635
Type Benchmarks.Middleware.JsonMessage         9.5   284,879,104  2,682  9.5     284,879,104  2,682   0      0 00110121121112111111112112222111 22,016.234 52,217.968

Analysis

We have more infrastructure allocation overhead than we do serializing the actual object.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions