dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
493 stars 191 forks source link

Reduce allocations in Razor's DirectiveVisitor #10537

Closed ToddGrun closed 3 months ago

ToddGrun commented 3 months ago

Noticed in customer trace, ~35% of allocations over a nearly two minute period are in razor's sourcegenerator's call to the TagHelperDirectiveVisitor.

As the DirectiveVisitor construction and usage are scoped to the calling method (DefaultRazorTagHelperContextDiscoveryPhase.ExecuteCore), it's easy enough to make the DirectiveVisitor disposable and to make the DirectiveVisitor use a pooled array for it's TagHelperDescriptor array.

from the customer trace image

ryzngard commented 3 months ago

@ToddGrun since this is a compiler change it will need 2 sign offs from that team prior to merging. Mine does not count towards that