Skip to content

Conversation

@ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Apr 8, 2025

This PR restores behavior introduced in #77768 that were reverted in PR #77983.
The revert occurred as it was flagged for causing ddrit regressions in some of the WinformsVS64.Designer tests. I was unable to reproduce this scenario locally,
but the RPS tests are able to reliably hit this issue.

Digging into it a bit indicated that creating the OpenTextBufferProvider on a bg thread somehow a thread affinity that caused
microsoft.visualstudio.shell.design.ni!DocData.CreateNativeDocData's call to msenv!CEditorManager::RegisterInvisibleEditor's to require an RPC main->bg thread switch.
This breaks the assumptions of RegisterInvisibleEditor and weird things start happening. Jason helped track down the likely culprit, and logged
https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2441480 to track that work.

This PR works around that issue by obtaining the RDT while on the main thread. I've logged #78050 to track the Roslyn cleanup
necessary once obtaining the rdt can be done from a background thread.

Compare by commit:

Commit 1:
Restore changes from PR #77768 that were reverted in PR #77983

Commit 2:
a) Ensure OpenTextBufferProvider._runningDocumentTable is initialized on the main thread.
b) Added comments about https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2441480 and created a tracking bug for us to clean this up once it's fixed (#78050)

@ToddGrun ToddGrun requested a review from a team as a code owner April 8, 2025 14:10
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 8, 2025
@ToddGrun ToddGrun changed the title Dev/toddgrun/4 8 open text buffer provider threading Move MiscellaneousFilesWorkspace construction to background thread Apr 8, 2025
@jjonescz
Copy link
Member

jjonescz commented Apr 8, 2025

I guess this is fine but we don't have clean main insertions yet, so maybe wait with this? cc @dibarbet as current Tiger

@ToddGrun
Copy link
Contributor Author

@jjonescz, @dibarbet -- is it a good time yet for this to move forward?

@ToddGrun
Copy link
Contributor Author

@jasonmalinowski -- any remaining concerns?

private readonly IVsService<IVsTextManager> _textManagerService;
private readonly OpenTextBufferProvider _openTextBufferProvider;
private readonly IMetadataAsSourceFileService _fileTrackingMetadataAsSourceService;
private readonly Lazy<IMetadataAsSourceFileService> _fileTrackingMetadataAsSourceService;
Copy link
Member

Choose a reason for hiding this comment

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

Was this necessary because that code also has affinity or just to avoid paying extra cost during creation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was also asked in the original PR. Generally, I'd prefer for lazy args for data not used immediately to delay construction.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. I'm not sure if we should have some sort of team habit to add comments to that effect. Historically we've used Lazy to mostly mean "there's deep magic here good luck" but if we were all better about being lazy then it's really those special cases that should be commented.

@ToddGrun
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@ToddGrun ToddGrun merged commit a85270b into dotnet:main Apr 12, 2025
28 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 12, 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

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.

4 participants