Repository navigation
Reduce allocations from Razor type inference - #86206
Merged
davidwengier merged 2 commits intoOct 26, 2026
Merged
Conversation
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Focused coverage of the custom enumerator’s lifecycle and interface behavior is missing, leaving its compatibility insufficiently verified for automated approval.
1 open issue
What changed in this PR
This PR reduces allocations in Razor generic-component processing by replacing temporary lists with pooled collections and LINQ-based child filtering with a struct enumerator.
Changes:
- Adds a typed child view and enumerator for component and markup nodes.
- Pools temporary lists used during generic-type inference and code generation.
- Preserves snapshots when removing dictionary entries during iteration.
| File | Description |
|---|---|
src/Razor/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/MarkupElementIntermediateNode.cs |
Uses typed views for attributes, captures, and keys. |
src/Razor/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/IntermediateNodeCollection.TypedEnumerable.cs |
Adds allocation-conscious filtering and enumeration. |
src/Razor/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/ComponentIntermediateNode.cs |
Uses typed views for component children. |
src/Razor/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentNodeWriter.cs |
Pools type-inference parameter lists. |
src/Razor/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentGenericTypePass.cs |
Pools temporary type-parameter and binding lists. |
Review effort: Balanced
akhera99
approved these changes
Oct 26, 2026
jasonmalinowski
approved these changes
Oct 26, 2026
This was referenced Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

In the dumps in https://developercommunity.visualstudio.com/t/Significant-intellisense-lag-when-adding/11169845 there were allocations showing up in handling generic components to do with
.ToList()and.OfType()usage. This replaces those with pooled lists, and a custom struct enumerator. I also rolled the changes out to other places with the same pattern, that didn't strictly show up in the dumps.Reductions are up to about 55% depending on the complexity of the Razor code being compiled, though to be fair some of the improvements are only around 5%.
Microsoft Reviewers: Open in CodeFlow