Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Optimize SqlClient primitive type writes #34048
When writing some primitive types to the tds packet stream small arrays are allocated and passed to the WriteByteArray function. I have changed WriteByteArray to WriteBytes and added a span parameter so that either a span or an array can be passed in (but not both, the priority is explained in the comments). The function will attempt to write using only a span unless it encounters an end of packet and needs to use an async continuation, in that case it will allocate an array and copy the remainder of the span into it. For primitive types this will rarely be needed.
These changes can be used to allow the new BitConverter.TryWriteBytes overload with stackalloced buffers to remove memory allocations for writing of 16 and 32 bit reals. This can be extended to guids at a later time.
This PR was split from #32811 and into smaller commits for easier review. It has passed the manual and efcore tests in native mode, the tests cannot be successfully run in managed mode due to #33930 . Performance improvements for this and related PR's are in the original discussion.
referenced this pull request
Dec 12, 2018
@dotnet-bot Test Windows x86 Release Build Please
01:00 != 00:00:00, dn:(UTC+01:00) Casablanca, sn:(UTC+01:00) Casablanca