[WIP] Attempt to reduce allocations coming in from SQLite backend#34790
[WIP] Attempt to reduce allocations coming in from SQLite backend#34790Therzok wants to merge 11 commits intodotnet:masterfrom
Conversation
|
There's a few more paths to optimize. Is this approach correct until now? I'm trying to figure out how to reduce async continuation allocations. |
src/Workspaces/Core/Portable/Storage/SQLite/Interop/SqlConnection.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Storage/SQLite/SQLitePersistentStorage_BulkPopulateIds.cs
Outdated
Show resolved
Hide resolved
|
cc @heejaechang |
|
Can you please include me on all sqlite changes. Thanks! |
src/Workspaces/Core/Portable/Storage/SQLite/Interop/SqlConnection.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Storage/SQLite/Interop/SqlConnection.cs
Outdated
Show resolved
Hide resolved
|
Styling fixed. I'll take a look at the other allocation sources. |
a527755 to
27f0ac7
Compare
There was a problem hiding this comment.
should this be ValueTask<SemaphoreDisposer>. Same question with a lot of your other changes?
There was a problem hiding this comment.
Could be. But given await SemaphoreSlim.WaitAsync() is not going to finish synchronously, this won't finish synchronously, so we still end up creating a Task.
There was a problem hiding this comment.
sure, in the async case, we'd allocate. But my gut makes me think in most cases we wouldn't be contentious. but maybe that should be examined in another PR :)
There was a problem hiding this comment.
Yeah, we'll get some benchmarks for this to see how it performs.
src/Compilers/Core/Portable/InternalUtilities/SemaphoreSlimExtensions.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Storage/SQLite/Interop/SqlConnection.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Storage/SQLite/Interop/SqlConnection.cs
Outdated
Show resolved
Hide resolved
|
Still working on more allocation paths, will add more commits until we get benchmarks for this. |
|
Not sure how to fix FlushSpecificWrites, as it's allocating a lot of capture classes. |
src/Compilers/Core/Portable/InternalUtilities/SemaphoreSlimExtensions.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/InternalUtilities/SemaphoreSlimExtensions.cs
Outdated
Show resolved
Hide resolved
maybe we should step back. do we know why this is happening? i think we often try to fix the symptom, but not necessarily the root cause. |
in terms of just fixing this, we could move to a model where we map from Key to a value-tuple of cached action, and the data the action would perform on. It will take a little code-finagling. but should be possible. |
1a6ed93 to
928404c
Compare
…sk completes synchronously
…path. The ContinueWith was still allocating another task instance.
sharwell
left a comment
There was a problem hiding this comment.
This change was superseded by a number of other recent changes. A huge thank you to @Therzok for the initial investigation, then multiple iterations of work to produce a viable and reproducible benchmark, and confirmation of the results from each individual change.
| } | ||
|
|
||
| public async static Task<SemaphoreDisposer> DisposableWaitAsync(this SemaphoreSlim semaphore, CancellationToken cancellationToken = default) | ||
| public static async ValueTask<SemaphoreDisposer> DisposableWaitAsync(this SemaphoreSlim semaphore, CancellationToken cancellationToken = default) |
There was a problem hiding this comment.
📝 This change was merged in #36128, largely due to the groundwork laid by this pull request
| } | ||
|
|
||
| public void RunInTransaction(Action action) | ||
| public TResult RunInTransaction<T, TResult>(T userData, Func<T, TResult> action) |
There was a problem hiding this comment.
📝 The equivalent of this change was merged in #36127, largely due to the groundwork laid by this pull request
cc @sharwell
Fixes #34789