Skip to content
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

Merged
merged 5 commits into from
Feb 28, 2024

Conversation

CyrusNajmabadi
Copy link
Member

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.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner February 27, 2024 19:07
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 27, 2024
namespace Microsoft.CodeAnalysis
namespace Microsoft.CodeAnalysis;

internal partial class SolutionCompilationState
{
Copy link
Member Author

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
Copy link
Member Author

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.

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

using var _1 = ArrayBuilder.GetInstance(alreadyParsedCount, out var documentsWithTrees);

I know you like to keep the concept count simple, but it seems like since the size is known, you might as well use ImmutableArray.Builder directly as there's no advantage to churning the arraypool here.

@@ -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 _));
Copy link
Contributor

Choose a reason for hiding this comment

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

s

static

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi merged commit 06df803 into dotnet:main Feb 28, 2024
27 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the nullCompilation branch February 28, 2024 00:27
@CyrusNajmabadi
Copy link
Member Author

@jasonmalinowski For review when you get back.

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