-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Avoid unnecessary project enumeration in SolutionState.Branch #53810
Conversation
@vatsalyaagrawal @jinujoseph This is for 16.11 |
analyzerReferences ??= AnalyzerReferences; | ||
projectIdToTrackerMap ??= _projectIdToTrackerMap; | ||
filePathToDocumentIdsMap ??= _filePathToDocumentIdsMap; | ||
dependencyGraph ??= _dependencyGraph; | ||
var newFrozenSourceGeneratedDocumentState = frozenSourceGeneratedDocument.HasValue ? frozenSourceGeneratedDocument.Value : _frozenSourceGeneratedDocumentState; | ||
|
||
// PERF: Only invoke WithLanguages if we have different set of project IDs (AddProject/RemoveProject operation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems sane. but i worry if it's possible to somehow have an Add+REmove processed at teh same time that woudl lead us to have the same count. @jasonmalinowski for validation that we do things in tiny steps, so this sort of optimization is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I audited the existing callsites to validate that they satisfy the first assertion. Definitely need @jasonmalinowski's confirmation on this one though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for some reason we also have a ProjectIds collection we pass around, and that's immutable. I'm guessing you're safe to do the WithLanguages any time the ProjectId collection object reference changes. The check is won't have false negatives where we fail to rerun WithLanguages; it could theoretically have a false positive where might run it if we manipulate the list and end up with the same original semantic value but I don't think we do that anywhere. (Or if we do, it's fine enough to not care since we'll still get quite the win.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that seems to be a much better approach. Let me adjust.
src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM as an optimization in theory. But i just want signoff from @jasonmalinowski that it's totally safe with how the WS forks.
src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs
Outdated
Show resolved
Hide resolved
Debug.Assert(idToProjectStateMap.Count != _projectIdToProjectStateMap.Count || | ||
idToProjectStateMap.Keys.SetEquals(_projectIdToProjectStateMap.Keys)); | ||
Debug.Assert(idToProjectStateMap.Count != _projectIdToProjectStateMap.Count || | ||
Options == Options.WithLanguages(GetRemoteSupportedProjectLanguages(idToProjectStateMap))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put these invariants in the CheckInvariants method? That way it'll get ran through places other than Branch, but actually at the constructor level.
…assert. We were not accounting for a new language. Additionally, also guard the added assert to only execute when input optionset for Branch method is null.
Alright, we have lot of test failures with this change. It seems it is not that trivial to add the optimization to skip For example, if we start with a workspace with an empty solution, and then do Going to ponder a bit more on this, marking the PR as draft meanwhile. |
Superseded by #54196 |
Fixes #53769