-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Related:
- Consider caching Utf8JsonWriter and PooledByteBufferWriter on a thread static in JsonSerializer.Serialize runtime#69889
- Implement a heuristic for using fast-path serialization in streaming JsonSerializer methods. runtime#78646
- Understand allocations discrepancies in Json benchmarks #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 will yield some benefits here already.