-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
What problem are you trying to solve?
Currently, the SqliteParameterBinder allocates memory unnecessarily. This is likely when using an array pool because the pooled arrays typically have a size larger than what is requests (rounded up to the power of 2).
efcore/src/Microsoft.Data.Sqlite.Core/SqliteParameterBinder.cs
Lines 15 to 23 in ccb0344
| var blob = value; | |
| if (ShouldTruncate(value.Length)) | |
| { | |
| blob = new byte[size!.Value]; | |
| Array.Copy(value, blob, size.Value); | |
| } | |
| var rc = sqlite3_bind_blob(stmt, index, blob); | |
| SqliteException.ThrowExceptionForRC(rc, handle); |
The underlying sqlite3_bind_blob accepts a ReadOnlySpan<byte>. I believe we can change the blob binding to take a ReadOnlySpan<byte> without any breaking changes (internal methods).
This would avoid the allocation.
Describe the solution you'd like
Don't copy byte arrays unless you really have to.