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

Microsoft.Data.Sqlite: Use Span overload of sqlite3_prepare #24331

Merged
merged 1 commit into from
Mar 8, 2021

Conversation

bricelam
Copy link
Contributor

@bricelam bricelam commented Mar 5, 2021

Removes a lot of unnecessary allocations and conversions from utf8

Fixes #16202

Here are some rough numbers from the Mixed Update Pipeline EF Core benchmark:

Mean Error StdDev Op/s Gen 0 Gen 1 Gen 2 Allocated
Before 660.5 ms 151.77 ms 8.32 ms 1.514 28000.0000 8000.0000 1000.0000 135.14 MB
After 628.8 ms 167.3 ms 9.17 ms 1.590 25000.0000 7000.0000 1000.0000 132.73 MB

@bricelam bricelam requested a review from a team March 5, 2021 19:54
@@ -470,15 +471,19 @@ private IEnumerable<sqlite3_stmt> PrepareAndEnumerateStatements(Stopwatch timer)
{
DisposePreparedStatements(disposing: false);

var byteCount = Encoding.UTF8.GetByteCount(_commandText);
var sql = new byte[byteCount + 1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use the ArrayPool here to further reduce the allocations?
Or if byteCount is small enough to stack-allocated the sql-buffer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have bigger plans to use this as a cache key, so I’ll wait to do optimizations like this as part of that work.

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐑 🇮🇹

Removes a lot of unnecessary allocations and conversions from utf8

Fixes dotnet#16202
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.

Microsoft.Data.Sqlite: Use Span overload of sqlite3_prepare_v2
3 participants