Skip to content

Avoid intermediary array allocation when computing checksums#63109

Merged
CyrusNajmabadi merged 7 commits intodotnet:mainfrom
CyrusNajmabadi:taskCleanup
Aug 2, 2022
Merged

Avoid intermediary array allocation when computing checksums#63109
CyrusNajmabadi merged 7 commits intodotnet:mainfrom
CyrusNajmabadi:taskCleanup

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

No description provided.

@ghost ghost added the Area-IDE label Aug 1, 2022
@CyrusNajmabadi CyrusNajmabadi changed the title Avoid intermediary allocation when computing checksums Avoid intermediary array allocation when computing checksums Aug 1, 2022
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review August 1, 2022 16:35
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner August 1, 2022 16:35
@CyrusNajmabadi CyrusNajmabadi requested a review from dibarbet August 1, 2022 16:35
var metadataReferenceChecksums = ChecksumCache.GetOrCreate<ChecksumCollection>(MetadataReferences, _ => new ChecksumCollection(MetadataReferences.SelectAsArray(r => serializer.CreateChecksum(r, cancellationToken))));
var analyzerReferenceChecksums = ChecksumCache.GetOrCreate<ChecksumCollection>(AnalyzerReferences, _ => new ChecksumCollection(AnalyzerReferences.SelectAsArray(r => serializer.CreateChecksum(r, cancellationToken))));

var documentChecksums = await Task.WhenAll(documentChecksumsTasks).ConfigureAwait(false);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this would make an array, that we would then copy over to an immutable array below. the new code avoids that intermediary array allocation.

foreach (var task in tasks)
result.Add(await task.ConfigureAwait(false));

return result.ToImmutableAndClear();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ToImmutableAndClear allows for an underlying call to MoveToImmutable. We likely should always be using it if we use the GetInstance form that takes a count. I'll open another PR on that.

@CyrusNajmabadi CyrusNajmabadi merged commit b4c49e3 into dotnet:main Aug 2, 2022
@ghost ghost added this to the Next milestone Aug 2, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the taskCleanup branch August 2, 2022 18:01
@dibarbet dibarbet modified the milestones: Next, 17.4 P2 Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants