-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Defer creating compilations for in-progress-states until actually needed. #72289
Conversation
namespace Microsoft.CodeAnalysis | ||
namespace Microsoft.CodeAnalysis; | ||
|
||
internal partial class SolutionCompilationState | ||
{ |
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.
view with whitespace off.
|
||
#if DEBUG |
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.
moved down to subclasses as it can't run during hte constructor now as the base types will not have setup CompilationWithoutGeneratedDocuments yet.
src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker.cs
Show resolved
Hide resolved
using var _2 = ArrayBuilder<SyntaxTree>.GetInstance(out var alreadyParsedTrees); | ||
var alreadyParsedCount = this.ProjectState.DocumentStates.States.Count(s => s.Value.TryGetSyntaxTree(out _)); | ||
|
||
using var _1 = ArrayBuilder<DocumentState>.GetInstance(alreadyParsedCount, out var documentsWithTrees); |
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.
@@ -703,15 +703,17 @@ public ICompilationTracker FreezePartialState(CancellationToken cancellationToke | |||
// parsed documents over to the new project state so we can preserve as much information as | |||
// possible. | |||
|
|||
using var _1 = ArrayBuilder<DocumentState>.GetInstance(out var documentsWithTrees); | |||
using var _2 = ArrayBuilder<SyntaxTree>.GetInstance(out var alreadyParsedTrees); | |||
var alreadyParsedCount = this.ProjectState.DocumentStates.States.Count(s => s.Value.TryGetSyntaxTree(out _)); |
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.
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.
@jasonmalinowski For review when you get back. |
When we freeze a solution, it is very common to freeze many projects that then will not have their compilations actually looked at. The current freezing mechanism produces compilations for all these projects no matter what. This is not free, and i've seen the number of compilations (and all the caches they creatE) show up in traces.
This approach moves us to delay actually creating the compilations until the point they are actually needed. This will be never for most projects in a large solution, as the vast majority of features that even freeze the solution in the first place will not even look outside of the projects/compilations in the current project cone.