-
I'm confused by the usages of I have an application that writes large JSON responses, and I'm writing this JSON manually with The ASP.NET Core docs say yes, but this SO post says no. Also, both the Also, if manual flushing is desired, how do I determine the optimum buffer size? I understand that it depends on the scenario, but still, some guidelines would be nice. My understanding is that each flushing would lead to one response chunk? Would 16 KB ( |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Both cases buffer and flush automatically based on internal heuristics—things like how
If you’re using |
Beta Was this translation helpful? Give feedback.
Newtonsoft.Json
isn’t async and doesn’t use the newer async APIs. So when it flushes buffered bytes to the underlying stream, it blocks—tying up a thread pool thread.SystemTextJsonOutputFormatter
, on the other hand, callsSerializeAsync
, which is key here.System.Text.Json
writes to the underlying writer as it serializes the object, and because it’s async, it doesn’t block a thread.Both cases buffer and flush automatically based on internal heuristics—things like how
StreamWriter
orJsonSerializer
are configured.