Skip to content

[WIP] Attempt to reduce allocations coming in from SQLite backend#34790

Closed
Therzok wants to merge 11 commits intodotnet:masterfrom
Therzok:sqlite-allocations
Closed

[WIP] Attempt to reduce allocations coming in from SQLite backend#34790
Therzok wants to merge 11 commits intodotnet:masterfrom
Therzok:sqlite-allocations

Conversation

@Therzok
Copy link
Copy Markdown
Contributor

@Therzok Therzok commented Apr 5, 2019

cc @sharwell

Fixes #34789

@Therzok Therzok requested a review from a team as a code owner April 5, 2019 13:27
@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented Apr 5, 2019

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.

@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented Apr 5, 2019

cc @heejaechang

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Can you please include me on all sqlite changes. Thanks!

@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented Apr 6, 2019

Styling fixed. I'll take a look at the other allocation sources.

@Therzok Therzok requested a review from a team as a code owner April 6, 2019 16:15
@Therzok Therzok force-pushed the sqlite-allocations branch from a527755 to 27f0ac7 Compare April 6, 2019 16:15
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this be ValueTask<SemaphoreDisposer>. Same question with a lot of your other changes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we'll get some benchmarks for this to see how it performs.

@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented Apr 6, 2019

Still working on more allocation paths, will add more commits until we get benchmarks for this.

@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented Apr 8, 2019

Not sure how to fix FlushSpecificWrites, as it's allocating a lot of capture classes.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Not sure how to fix FlushSpecificWrites, as it's allocating a lot of capture classes.

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.

@vatsalyaagrawal vatsalyaagrawal added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Apr 8, 2019
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Not sure how to fix FlushSpecificWrites, as it's allocating a lot of capture classes.

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.

@Therzok Therzok force-pushed the sqlite-allocations branch from 1a6ed93 to 928404c Compare April 8, 2019 18:22
Copy link
Copy Markdown
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 The equivalent of this change was merged in #36127, largely due to the groundwork laid by this pull request

@sharwell sharwell closed this Jun 8, 2019
@sharwell sharwell added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Jun 8, 2019
@Therzok Therzok deleted the sqlite-allocations branch August 21, 2019 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lots of capture classes allocations in SQLitePersistentStorage

6 participants