Skip to content

Simplify initialization of OpenFileTracker#79281

Merged
jasonmalinowski merged 1 commit intodotnet:mainfrom
jasonmalinowski:simplify-openfiletracker-initialization
Jul 10, 2025
Merged

Simplify initialization of OpenFileTracker#79281
jasonmalinowski merged 1 commit intodotnet:mainfrom
jasonmalinowski:simplify-openfiletracker-initialization

Conversation

@jasonmalinowski
Copy link
Member

There's only two things here that could potentially need the UI thread:

  1. The Running Document Table subscription, but OpenTextBufferProvider already abstracted that away.
  2. The IEditorOptionsFactoryService usage, which being a MEF component shouldn't care, but even then we don't need it right away.

It's easy to clean all this up, so just do so.

@jasonmalinowski jasonmalinowski self-assigned this Jul 8, 2025
@jasonmalinowski jasonmalinowski requested a review from a team as a code owner July 8, 2025 01:02
var solutionClosingContext = UIContext.FromUIContextGuid(VSConstants.UICONTEXT.SolutionClosing_guid);
solutionClosingContext.UIContextChanged += (_, e) => ProjectSystemProjectFactory.SolutionClosing = e.Activated;

var openFileTracker = await OpenFileTracker.CreateAsync(this, ProjectSystemProjectFactory, asyncServiceProvider).ConfigureAwait(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

var openFileTracker = await OpenFileTracker.CreateAsync(this, ProjectSystemProjectFactory, asyncServiceProvider).ConfigureAwait(true);

Does the SwitchToMainThreadAsync call above still need to always yield since the amount of work being done is much less now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, maybe getting the telemetry session is still potentially costly

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a pretty old dependency, might be worth checking whether that still needs to happen on the ui thread

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm ahead of you! #79282

Copy link
Member Author

Choose a reason for hiding this comment

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

And @davkean confirmed the session is created really early during VS startup, so no worries about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Is the yielding on the main thread switch still worthwhile then?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm leaving it, since once this is in, I'm doing a follow-up to delete the initialize method entirely since the only remaining work would be the UIContext stuff which doesn't need the UI thread anymore either.

@jasonmalinowski jasonmalinowski force-pushed the simplify-openfiletracker-initialization branch 3 times, most recently from c8cbf5b to 7051de1 Compare July 9, 2025 21:25
There's only two things here that could potentially need the UI thread:

1. The Running Document Table subscription, but OpenTextBufferProvider
   already abstracted that away.
2. The IEditorOptionsFactoryService usage, which being a MEF component
   shouldn't care, but even then we don't need it right away.

It's easy to clean all this up, so just do so.
@jasonmalinowski jasonmalinowski force-pushed the simplify-openfiletracker-initialization branch from 7051de1 to 2193401 Compare July 9, 2025 23:14
@jasonmalinowski jasonmalinowski merged commit 61f9028 into dotnet:main Jul 10, 2025
25 checks passed
@jasonmalinowski jasonmalinowski deleted the simplify-openfiletracker-initialization branch July 10, 2025 00:42
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 10, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
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.

4 participants