You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reduce allocations related to SyntaxListBuilder (#9612)
A couple days ago, @ToddGrun pointed me to some [Prism
data](https://prism.vsdata.io/failure/?query=ch%3Drelease%20r%3D17.8&eventType=allocation&failureType=dualdirection&failureHash=30151e5e-e8aa-2e4c-a22f-106e4d7f8e6c)
indicating that there's a lot of allocation due to
`SyntaxListBuilder.Grow(...)`. I dug in and made several changes that
should improve things.
1. `SyntaxListBuilder` is now pooled everywhere it's used. The builders
contain single arrays that can grow to a maximum of 512 entries. That
should eliminate the allocations that we're seeing in
`SyntaxListBuilder.Grow(...)`.
2. I introduced a `ChildNodesHelper` struct to avoid boxing
`ChildSyntaxList` to an `IReadOnlyList<SyntaxNode>` just to call
`Skip(1).ToList()` in a special case.
3. Updated code to avoid boxing `ImmutableArray<SyntaxTree>` to
`IReadOnlyList<SyntaxTree>` for imports.
4. Added helpers to avoid calling params arrays.
There are some unrelated clean up changes, so it might be useful to
review a commit at a time if those changes get in the way:
1. I've annotated `SyntaxNode`, `SyntaxList`, `SyntaxList<T>`,
`SyntaxListBuilder` and `SyntaxListBuilder<T>` for nullability.
2. I renamed the misspelled API, `RazorEnginePhaseBase.OnIntialized()`
to `RazorEnginePhaseBase.OnInitialized()`.
5. I refactored similar code in `FormattingVisitor` and
`ClassifiedSpanVisitor` to be shared. These algorithms were pretty much
identical, and I decided to refactor rather than update the code in both
places.
0 commit comments