-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
This removes ~30MB of LOH allocations when compiling Roslyn
@@ -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; |
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.
💡 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.
@dotnet/roslyn-compiler PTAL |
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>() |
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.
nit: consider changing var to SegmentedList here and using a collection-expr
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