odata.net icon indicating copy to clipboard operation
odata.net copied to clipboard

Allow `ODataUtf8JsonWriter` buffer size to be configurable by the user.

Open habbes opened this issue 3 months ago • 0 comments

A customer wants to be able to configure the buffer size of ODataUtf8JsonWriter, e.g. increase the buffer size to reduce how frequent stream I/O is invoked. While ODataUtf8JsonWriter accepts a buffer size as a constructor parameter, this parameter is not exposed on the IJsonWriterFactory interface or any of the built-in implementations of that interface. ODataMessageWriter has a BufferSize property, but that's only used when using the "older" JsonWriter.

There are some existing design issues that make this feature request less straightforward:

  • Changing the signature of IJsonWriterFactory methods would be breaking
  • We could add a buffer size parameter to the default implementation without a breaking change, but there would now be two places where a BufferSize option is exposed, which could be confusing to users: ODataMessageWriter.BufferSize setting, and the proposed default JSON writer ffactory buffer size option (e.g. Constructor parameter)
  • The default buffer size in ODataMessageWriter.BufferSize is different (and higher) than the default buffer size in ODataUtf8JsonWriter. Changing the default buffer size to a higher could have visible side-effects on customers who are already aware of the ODataUtf8JsonWriter's buffer size and prefer its smaller memory footprint.

If the issue https://github.com/OData/odata.net/issues/3099 is addressed, a workaround would be for the user to wrap the output stream behind a custom stream implementation that intercepts writes and users a buffer size the user desires, then pass that stream to ODataMessageWriter.

Assemblies affected

Microsoft.OData.Core 7.x and 8.x

Reproduce steps

N/A

Expected result

There's no way for the user to configure the ODataUtf8JsonWriter buffer size

Actual result

There should be a way to control the buffer size of ODataUtf8JsonWriter

habbes avatar Oct 25 '24 19:10 habbes