JsonSerializerOptions DefaultBufferSize for ASP.NET Core with source generator #96919
-
Source generated JSON serialization code is only invoked for response serialization in ASP.NET Core if the response size is less than half of the JsonSerializerOptions.DefaultBufferSize. What is the best way to tune the setting, when most of the responses are within the default size, but there are a few very frequent responses that are close to MB (over the default limit)? Does it make sense to set 2 MB buffer size, even if it allocates the buffer pool on the LOH? If I keep the limit as default, it does not allocate the buffer pool on the LOH, but these large responses for every request would still allocate a temporary buffer on the heap? (seemingly making this even less attractive) As I understand this is a "streaming" scenario with ASP.NET Core, meaning it is the async version of the serialize methods. Based on the remarks it is unclear if increasing the size to a MB is reasonable choice. I wonder if @eiriktsarpalis has some thoughts about this too. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
To clarify, the source generator is being used regardless of what the response size is. What changes really is whether fast-path or metadata-based source generator modes are being called. I can't clear any clear recommendations here, but ultimately this a matter of trade-offs. How important is the added throughput of fast-path for your application, and is it pooling larger buffers to achieve it worth it? |
Beta Was this translation helpful? Give feedback.
To clarify, the source generator is being used regardless of what the response size is. What changes really is whether fast-path or metadata-based source generator modes are being called.
I can't clear any clear recommendations here, but ultimately this a matter of trade-offs. How important is the added throughput of fast-path for your application, and is it pooling larger buffers to achieve it worth it?