Skip to content

Warm up ImportCompletion cache in background when opening a document#55729

Merged
genlu merged 6 commits intodotnet:mainfrom
genlu:CacheWarmUp
Aug 30, 2021
Merged

Warm up ImportCompletion cache in background when opening a document#55729
genlu merged 6 commits intodotnet:mainfrom
genlu:CacheWarmUp

Conversation

@genlu
Copy link
Copy Markdown
Member

@genlu genlu commented Aug 19, 2021

Closes #37197

@ghost ghost added the Area-IDE label Aug 19, 2021
@genlu genlu marked this pull request as ready for review August 19, 2021 20:38
@genlu genlu requested a review from a team as a code owner August 19, 2021 20:38
@genlu
Copy link
Copy Markdown
Member Author

genlu commented Aug 26, 2021

@CyrusNajmabadi @sharwell Please take a look, thanks!

if (s_cachingTask.IsCompleted)
{
s_cachingTask = Task.Run(() => GetCacheEntriesAsync(currentProject, syntaxContext, forceCacheCreation: true, CancellationToken.None));
// When building cache in the background, make sure we always use latest snapshot with full semantic
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.

❔ Can we make the call twice? First time uses partial semantics to get a mostly-correct cache quickly, and then before returning it waits for full semantics?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That sounds reasonable

Comment on lines +66 to +67
_typeTask = _typeTask.ContinueWith(_ => PopulateTypeImportCompletionCacheAsync(this.Workspace.CurrentSolution.GetDocument(documentId)), TaskScheduler.Default);
_extensionMethodTask = _extensionMethodTask.ContinueWith(_ => PopulateExtensionMethodImportCompletionCacheAsync(this.Workspace.CurrentSolution.GetDocument(documentId)), TaskScheduler.Default);
Copy link
Copy Markdown
Contributor

@sharwell sharwell Aug 27, 2021

Choose a reason for hiding this comment

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

❔ Why is this using task chains instead of just two local variables?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To avoid the backgrounds tasks taking up too much resources calculating the cache if user opened a lot of files.

if (s_cachingTask.IsCompleted)
{
s_cachingTask = Task.Run(() => GetCacheEntriesAsync(currentProject, syntaxContext, forceCacheCreation: true, CancellationToken.None));
// When building cache in the background, make sure we always use latest snapshot with full semantic
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.

💭 It seems like a future change could consolidate the calculation strategies for these two similar services. I definitely do not want to include it here (where it would delay a big improvement).

@genlu genlu enabled auto-merge August 27, 2021 21:33
@genlu genlu merged commit 8de6661 into dotnet:main Aug 30, 2021
@ghost ghost added this to the Next milestone Aug 30, 2021
@genlu genlu deleted the CacheWarmUp branch August 30, 2021 20:21
@dibarbet dibarbet modified the milestones: Next, 17.0.P4 Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import completion might benifit from persisting data to disk and pre-calculation

4 participants