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

Using Segmented collections to avoid LOH allocations #72656

Merged
merged 2 commits into from
Mar 25, 2024
Merged

Conversation

jaredpar
Copy link
Member

@jaredpar jaredpar commented Mar 21, 2024

Profiling revealed that these collections are resulting in large LOH allocations in the compiler. Flipping to Segmented collections to avoid the LOH. In total these changes remove 200MB+ of allocations from the LOH heap.

This results in significant improvements to the GC when running the compiler

image

image

This removes ~30MB of LOH allocations when compiling Roslyn
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 21, 2024
@@ -942,28 +943,28 @@ protected virtual TextLineCollection GetLinesCore()
internal sealed class LineInfo : TextLineCollection
{
private readonly SourceText _text;
private readonly int[] _lineStarts;
private readonly SegmentedList<int> _lineStarts;
Copy link
Member

Choose a reason for hiding this comment

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

💡 This could likely be changed to an ImmutableSegmentedList<int> with minimal penalty. Note that there is not currently a way to create the builder for that with a specific capacity, but I'm already working on a change to add that.

@jaredpar jaredpar changed the title Experimenting with segmented collection changes Using Segmented collections to avoid LOH allocations Mar 22, 2024
@jaredpar jaredpar marked this pull request as ready for review March 22, 2024 20:28
@jaredpar jaredpar requested a review from a team as a code owner March 22, 2024 20:28
@jaredpar
Copy link
Member Author

@dotnet/roslyn-compiler PTAL

@RikkiGibson
Copy link
Contributor

Did perfview generate the tables in the PR description?

@jaredpar
Copy link
Member Author

Did perfview generate the tables in the PR description?

Yes this is from the GC Stats view.

}

var lineStarts = ArrayBuilder<int>.GetInstance();
lineStarts.Add(0); // there is always the first line
var lineStarts = new SegmentedList<int>()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: consider changing var to SegmentedList here and using a collection-expr

@jaredpar jaredpar merged commit f8e3bc1 into dotnet:main Mar 25, 2024
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Mar 25, 2024
@jaredpar jaredpar deleted the sl2 branch March 25, 2024 17:23
@RikkiGibson RikkiGibson modified the milestones: Next, 17.10 P3 Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers 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.

None yet

4 participants