-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Pass read only span to SQLite raw to avoid allocation #37436
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
Conversation
Summary of changes - Use read only span for blob parameter binding - Add benchmark to demonstrate savings
benchmark/EFCore.Sqlite.Benchmarks/EFCore.Sqlite.Benchmarks.csproj
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR optimizes SQLite blob parameter binding by changing the BindBlob method signature from byte[] to ReadOnlySpan<byte>, reducing memory allocations when large byte arrays are truncated. The benchmark results show approximately 50% reduction in memory allocations.
Key Changes
- Modified
BindBlobabstract method to acceptReadOnlySpan<byte>instead ofbyte[] - Updated truncation logic to use
Sliceinstead ofArray.Copy, eliminating temporary array allocation - Added comprehensive benchmark tests to verify the optimization
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| SqliteValueBinder.cs | Changed abstract method signature to use ReadOnlySpan<byte> |
| SqliteResultBinder.cs | Updated implementation to match new signature, added using System |
| SqliteParameterBinder.cs | Replaced Array.Copy with Slice for efficient truncation |
| EFCore.Sqlite.Benchmarks.csproj | Added SQLitePCL package reference for benchmarks |
| BlobBindingTests.cs | New benchmark class to measure allocation improvements |
cincuranet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joelverhagen Great contributions. Thanks. Just some final cleanup and this is ready to go.
Addresses #37435
Before
After
The test reduces the array size by 1 byte so the allocation is roughly half as expected.