MicrosoftDocs / OData-docs

Creative Commons Attribution 4.0 International
33 stars 110 forks source link

Show how to read large field values (e.g. strings, binary values) into streams with ODataMessageReader #337

Open habbes opened 1 week ago

habbes commented 1 week ago

When you have fields which large values, usually strings or binary data encoded as base64 strings, deserializing these fields might lead to large heap allocations due to reading the entire value into memory. ODataMessageWriter exposes a ReadAsStreamFunc property that the user can assign a delegate that returns true for any property that should be deserialized into a stream. This feature is not documented but is useful work performance-sensitive services working which large payloads.

Basically, there are two steps:

Here's a test that demonstrates the feature: https://github.com/OData/odata.net/blob/release-7.x/test/FunctionalTests/Microsoft.OData.Core.Tests/JsonLight/ODataJsonLightReaderTests.cs#L846

We should add a tutorial article this and/or mention it in the performance guidelines