-
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
SqliteCommand allocates one Stopwatch per every query or prepare #26295
Comments
@vonzshik "They can be allocated once per SqliteConnection." So, is this simply a case of declaring the 'timer' Stopwatch as a field instead of a method variable? |
@Dr-Ogden-Wernstrom more like an internal property on internal Stopwatch Timer { get; } = new(); The main question here is, should the instance of |
Thanks @vonzshik, understood. I've never contributed before but would like to try these options out, see what works best, and take a crack at a PR. |
So I think it makes more sense to hold the StopWatch on SqliteConnection rather than SqlConnectionInternal because an internal connection is created each time the connection is opened (and destroyed each time the connection is closed). The same stopwatch can be re-used by all instances of SqliteConnectionInternal that SqliteConnection creates. |
@Dr-Ogden-Wernstrom not unless pooling is enabled (which it is by default). |
@vonzshik Ok (can't believe I missed that). So makes more sense to put on the internal connection (internal getter with initializer) and put another internal property on SqliteConnection that simply passes through the timer from the internal connection, or returns null if called when the connection has not yet been opened. The only downside is when pooling is disabled then an allocation is made each time the connection is opened, however since this is not the default setting and still this is better than the current code, so this is acceptable? |
@Dr-Ogden-Wernstrom pooling is a very new feature (it should be released together with 6.0 release), so not a lot of people actually know about that)
Pretty much, yes. Although, I'm not sure internal Stopwatch Timer
{
get
{
Debug.Assert(_innerConnection != null);
return _innerConnection!.Timer;
}
} |
@vonzshik That it never returns null I did spot. However, I reasoned that the property itself doesn't know that it's always called when it has a value. Only the calling code knows that. So I thought maybe more appropriate to define the property on SqliteConnection as
and use null-forgiving from SqliteCommand.PrepareAndEnumerateStatements
I've pushed a commit with this in so you can see more fully: https://github.com/Dr-Ogden-Wernstrom/efcore/commit/d03467ff09b0326ee33e718fa9bb9c725549258c That's what I would do if it were my project anyway. But I'm happy to follow your lead on this one. |
@Dr-Ogden-Wernstrom but you could just do the same at the Anyway, I think the best way to go forward is to submit a pr, where we will discuss further. |
Hi @vonzshik and @Dr-Ogden-Wernstrom This hasn't been touch for a while - would it be ok I looked into it? |
@3schwartz Note that the previous PR was closed--see #26495. Probably only worth looking into if you have some other way of doing it that won't hit the same issues. |
I wasn't aware if that. I will find another first good issue then. |
Note from triage: does not seem to be a good way of doing this. |
efcore/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs
Line 259 in 9b66f4c
efcore/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs
Line 310 in 9b66f4c
They can be allocated once per SqliteConnection.
The text was updated successfully, but these errors were encountered: