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

Small optimization around ProjectState modification operations #72313

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,9 @@ public AnalyzerReference GetAnalyzerReferenceForGenerator(ISourceGenerator gener

public ProjectState AddDocuments(ImmutableArray<DocumentState> documents)
{
if (documents.IsEmpty)
return this;

Debug.Assert(!documents.Any(d => DocumentStates.Contains(d.Id)));

return With(
Expand All @@ -774,6 +777,9 @@ public ProjectState AddDocuments(ImmutableArray<DocumentState> documents)

public ProjectState AddAdditionalDocuments(ImmutableArray<AdditionalDocumentState> documents)
{
if (documents.IsEmpty)
return this;

Debug.Assert(!documents.Any(d => AdditionalDocumentStates.Contains(d.Id)));

return With(
Expand All @@ -783,6 +789,9 @@ public ProjectState AddAdditionalDocuments(ImmutableArray<AdditionalDocumentStat

public ProjectState AddAnalyzerConfigDocuments(ImmutableArray<AnalyzerConfigDocumentState> documents)
{
if (documents.IsEmpty)
return this;

Debug.Assert(!documents.Any(d => AnalyzerConfigDocumentStates.Contains(d.Id)));

var newAnalyzerConfigDocumentStates = AnalyzerConfigDocumentStates.AddRange(documents);
Expand Down Expand Up @@ -811,6 +820,9 @@ private ProjectState CreateNewStateForChangedAnalyzerConfigDocuments(TextDocumen

public ProjectState RemoveDocuments(ImmutableArray<DocumentId> documentIds)
{
if (documentIds.IsEmpty)
return this;

// We create a new CachingAnalyzerConfigSet for the new snapshot to avoid holding onto cached information
// for removed documents.
return With(
Expand All @@ -821,20 +833,29 @@ public ProjectState RemoveDocuments(ImmutableArray<DocumentId> documentIds)

public ProjectState RemoveAdditionalDocuments(ImmutableArray<DocumentId> documentIds)
{
if (documentIds.IsEmpty)
return this;

return With(
projectInfo: ProjectInfo.WithVersion(Version.GetNewerVersion()),
additionalDocumentStates: AdditionalDocumentStates.RemoveRange(documentIds));
}

public ProjectState RemoveAnalyzerConfigDocuments(ImmutableArray<DocumentId> documentIds)
{
if (documentIds.IsEmpty)
return this;

var newAnalyzerConfigDocumentStates = AnalyzerConfigDocumentStates.RemoveRange(documentIds);

return CreateNewStateForChangedAnalyzerConfigDocuments(newAnalyzerConfigDocumentStates);
}

public ProjectState RemoveAllDocuments()
public ProjectState RemoveAllNormalDocuments()
{
if (DocumentStates.IsEmpty)
return this;

// We create a new CachingAnalyzerConfigSet for the new snapshot to avoid holding onto cached information
// for removed documents.
return With(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ InProgressState BuildInProgressStateFromNoCompilationState()
// other. It also means that if we're in the process of parsing documents in that chain, that
// we'll see the results of how far we've gotten if someone asks for a frozen snapshot midway
// through.
var initialProjectState = this.ProjectState.RemoveAllDocuments();
var initialProjectState = this.ProjectState.RemoveAllNormalDocuments();
var initialCompilation = this.CreateEmptyCompilation();

var translationActionsBuilder = ImmutableList.CreateBuilder<TranslationAction>();
Expand Down Expand Up @@ -723,7 +723,7 @@ public ICompilationTracker FreezePartialState(CancellationToken cancellationToke

// Transition us to a state that only has documents for the files we've already parsed.
var frozenProjectState = this.ProjectState
.RemoveAllDocuments()
.RemoveAllNormalDocuments()
.AddDocuments(documentsWithTreesBuilder.ToImmutableAndClear());

// Defer creating these compilations. It's common to freeze projects (as part of a solution freeze)
Expand Down
Loading