-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Change timer from method variable to property of SqlConnectioninteral #26495
Closed
Closed
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d03467f
Host timer as property on SqliteConnectionInternal.
Russell-Horwood-Xceptor a5b7dee
Merge branch 'dotnet:main' into 26295_SqliteTimerAsField
97fbfed
Summary of the changes
Russell-Horwood-Xceptor 2c0520a
Merge branch '26295_SqliteTimerAsField' of https://github.com/Dr-Ogde…
Russell-Horwood-Xceptor 0581078
Update src/Microsoft.Data.Sqlite.Core/SqliteConnectionInternal.cs
af8f49f
Summary of the changes
Russell-Horwood-Xceptor e9ba6d3
Merge from remote.
Russell-Horwood-Xceptor 1abe9e8
Summary of the changes
Russell-Horwood-Xceptor 2431c1d
Merge branch 'main' into 26295_SqliteTimerAsField
827b12e
Fix my merge-by-eye fail.
Russell-Horwood-Xceptor 44ca0ca
Fix my merge-by-eye fail.
Russell-Horwood-Xceptor 08a8b2a
Merge branch '26295_SqliteTimerAsField' of https://github.com/Dr-Ogde…
Russell-Horwood-Xceptor f5649e9
Merge branch '26295_SqliteTimerAsField' of https://github.com/Dr-Ogde…
Russell-Horwood-Xceptor 7d53c2d
Merge branch '26295_SqliteTimerAsField' of https://github.com/Dr-Ogde…
Russell-Horwood-Xceptor dfd9adc
Merge branch 'main' into 26295_SqliteTimerAsField
Russell-Horwood-Xceptor 685a862
Instantiate timer iff the command is the only one on the connection
Russell-Horwood-Xceptor f2ef784
Same timer prepare and reading statements
Russell-Horwood-Xceptor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This doesn't seem right to me. A connection can have multiple readers open at the same time. I'm pretty sure we need a new instance for every reader...
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.
Would using something like ValueStopwatch instead also help perf?
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.
See dotnet/runtime#48570 for some discussion on ValueStopWatch (which was closed for some reason).
If we don't do ValueStopWatch, we can still "pool" a single StopWatch instance on the connection, so that uses which don't involve multiple open readers can benefit (but those with multiple readers would allocate).
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.
Huh, didn't know Sqlite supported MARS...
To me, using
ValueStopwatch
seems to be the simplest solution (in a sense that there is no pooling involved, which does complicate things a bit), but pooling is also fine.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.
Okay,
ValueStopwatch
in a way it's implemented in ASP.NET Core wouldn't work here. The main offender isSqliteDataReader
:efcore/src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs
Lines 157 to 173 in afe299f
Every time a
NextResult
is called on a reader the timer isn't reset, but continues to measure the elapsed time from where it left on a previous call.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.
@roji Could this be something as simple as allocating a new Stopwatch if the connection has multiple commands like my latest change?
@vonzshik My initial feeling is that adding stop/start functionality to ValueStopwatch would result in something almost the same as the standard Stopwatch implementation, so not much benefit. What do you think?
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.
Well, there is the fun fact that both
SqliteCommand.PrepareAndEnumerateStatements
andSqliteDataReader.NextResult
are supposed to use the exact same instance ofStopwatch
and the result fromSqliteCommand.PrepareAndEnumerateStatements
is passed asIEnumerable
to the reader...efcore/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs
Line 313 in 802d4c5
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.
Hey @vonzshik, that is a fun fact.
Sorry, I've been so slow getting to this, and for being a total noob on this project, but would you mind taking another look, please.