Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON: use Encoding.CreateTranscodingStream when reading JSON in materializer #31220

Open
maumar opened this issue Jul 10, 2023 · 0 comments
Open

Comments

@maumar
Copy link
Contributor

maumar commented Jul 10, 2023

          The end result seems to be thing: 
new MemoryStream(Encoding.UTF8.GetBytes(dataReader.GetFieldValue<string>(0)))

Regardless of ADO.NET drivers where we can get UTF8 directly out (#31216), we can optimize this by using Encoding.CreateTranscodingStream over a simple Stream to read the string as raw bytes:

Span<byte> buffer = // buffer to read into
var jsonValue = "{}";
MemoryMarshal.Cast<char, byte>(jsonValue.AsSpan(0, Math.Min(jsonValue.Length, buffer.Length / 2))).CopyTo(buffer);

Thanks to @NinoFloris for pointing out all the above.

Originally posted by @roji in #31160 (comment)

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

No branches or pull requests

2 participants