dotnet / dotnet/aspnetcore

Investigate options to allow pooling of JSON serialization infrastructure

Open
#45,332 2 comments 0 reactions 0 assignees View on GitHub
area-minimal feature-minimal-actions Perf
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

Related:
- dotnet/runtime#69889
- dotnet/runtime#78646
- #45330

Our JSON-related extension methods on `HttpResponse` today and the inherent JSON serialization implemented by Minimal APIs (either directly from route handler returned objects or the JSON `IResult` types) call through the JSON serializers async code paths. These paths don't implement any pooling for the underlying infrastructure like `Utf8JsonWriter` resulting in repeated allocations of those types, which for small payloads can represent the majority of allocations for the related requests.

We should explore options to enable these features to either pool the underlying types or instead go through the synchronous code paths of `JsonSerializer` instead, as they implement pooling under the covers, with appropriate heuristics or options to ensure expectations around memory allocations, back pressure, etc. are maintained.

Note it's possible [existing ongoing work in the runtime](https://github.com/dotnet/runtime/pull/78646) will yield some benefits here already.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.