Skip to content

ArrayBufferWriter instead of MemoryStream for Utf8JsonWriter#341

Draft
erwinkramer wants to merge 1 commit intocloudevents:mainfrom
erwinkramer:main
Draft

ArrayBufferWriter instead of MemoryStream for Utf8JsonWriter#341
erwinkramer wants to merge 1 commit intocloudevents:mainfrom
erwinkramer:main

Conversation

@erwinkramer
Copy link
Copy Markdown
Contributor

Instead of doing ToArray we can do WrittenMemory to return the (readonly) memory, this should reduce allocation, memory and improve speed.

This won't work on netstandard2.0, the writer isn't included via System.Buffers... so if you like this setup then 3 methods will get different signatures for the old frameworks, which isn't elegant. This draft just displays the basic intention.

Signed-off-by: Erwin <erwinkramer@hotmail.com>
@erwinkramer
Copy link
Copy Markdown
Contributor Author

@jskeet let me know your thoughts

@jskeet
Copy link
Copy Markdown
Contributor

jskeet commented Apr 10, 2026

Will do when I can, but I don't know when I'll get to it. Maybe over the weekend, but I'm not promising.

@jskeet
Copy link
Copy Markdown
Contributor

jskeet commented Apr 11, 2026

Given that this one looks pretty fiddly, I think it would be good to compare performance. If it's only a small part of the performance penalty, it may not be worth it... if it makes a huge difference, it's worth looking at. Having some benchmarks for the project would be a good thing in general...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants