Skip to content

Another small set of package initialization optimizations #77646

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

Conversation

ToddGrun
Copy link
Contributor

  1. Move RegisterLanguageService call in AbstractPackage<> to be on the background. This method was already thread safe.

  2. Move RegisterMiscellaneousFilesWorkspaceInformation call in AbstractPackage<> to be on the background. This required changing the data structure holding these strings to be a concurrent dictionary.

  3. Move RegisterObjectBrowserLibraryManager call in AbstractPackge package initialization to OnAfterPackageLoadedAsync

  4. Change MiscellaneousFilesWorkspace to not require a bg thread initialize call and instead get the text manager when needed.

1) Move RegisterLanguageService call in AbstractPackage<> to be on the background. This method was already thread safe.
2) Move RegisterMiscellaneousFilesWorkspaceInformation call in AbstractPackage<> to be on the background. This required changing the data structure holding these strings to be a concurrent dictionary.
3) Move RegisterObjectBrowserLibraryManager call in AbstractPackge package initialization to OnAfterPackageLoadedAsync
4) Change MiscellaneousFilesWorkspace to not require a bg thread initialize call and instead get the text manager when needed.
@ToddGrun ToddGrun requested a review from a team as a code owner March 17, 2025 21:59
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 17, 2025
Comment on lines +72 to +73
// Ensure we're on the BG when creating the language service.
await TaskScheduler.Default;
Copy link
Member

@jasonmalinowski jasonmalinowski Mar 18, 2025

Choose a reason for hiding this comment

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

We already said isMainThreadTask: false, why saying this a second time? I'd frankly can't explain why that RegisterLanguageServer function exists in the first place, if that was the concern. It has this comment:

// When registering a language service, we need to take its ComAggregate wrapper.

But there's nothing special it's doing with it...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the callback when the service is created, I don't know if we can guarantee what context we are on when that happens.

Copy link
Member

Choose a reason for hiding this comment

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

Oh right of course. That'd be something we should follow up with -- hopefully we have some way to say we can be created on a background thread -- it'd be silly for the service system to bounce to the UI thread if we didn't need it.


return _languageService.ComAggregate!;
});

var miscellaneousFilesWorkspace = this.ComponentModel.GetService<MiscellaneousFilesWorkspace>();
Copy link
Member

@jasonmalinowski jasonmalinowski Mar 18, 2025

Choose a reason for hiding this comment

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

Moving this to the background should be safe -- this is not written to have UI thread assumptions in the constructors. See the comments in OpenTextBufferProvider's constructor specifically for ensuring that's safe. This wasn't the case a few years back but this was generally modernized.

If you're wanting to keep the changes small to manage risk better, do this in a follow up PR (but don't forget about it.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally tried that and it threw. Let me see if I can find out where that dependency is.

Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Any comments can be deferred.

@ToddGrun
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@ToddGrun ToddGrun merged commit e4120e1 into dotnet:release/dev18.0 Mar 18, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants