-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Small memory allocation optimization in DefaultRazorTagHelperBinderPh… #22887
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
Small memory allocation optimization in DefaultRazorTagHelperBinderPh… #22887
Conversation
…ase.TrySplitNamespaceAndType This method allocated multiple strings on every invocation when they were rarely needed. With this change, I see a reduction in memory allocated during RazorProjectEngine.ProcessDesignTime of 1.4%.
| typeName = GetTextSpanContent(typeNameTextSpan, typeName); | ||
| } | ||
| if (!TrySplitNamespaceAndType(typeName, out var _, out var className)) | ||
| if (!TrySplitNamespaceAndType(typeName, out var _, out var classNameTextSpan)) |
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.
Minor but this method could exit earlier if the original typeName were empty. No reason to get the string content of an empty span. #WontFix
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.
I didn't want to affect the functionality of this code, as there are some subtle behaviors here. Let me know if you think it's worth pursuing.
In reply to: 439606336 [](ancestors = 439606336)
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.
Not my code. I defer to other reviewers 😺
ajaybhargavb
left a comment
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.
🎉
src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorTagHelperBinderPhase.cs
Show resolved
Hide resolved
src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorTagHelperBinderPhase.cs
Show resolved
Hide resolved
|
|
||
| // Internal for testing. | ||
| internal static bool TrySplitNamespaceAndType(string fullTypeName, out string @namespace, out string typeName) | ||
| internal static bool TrySplitNamespaceAndType(string fullTypeName, out TextSpan @namespace, out TextSpan typeName) |
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.
Nice
…ase.TrySplitNamespaceAndType
This method allocated multiple strings on every invocation when they were rarely needed. With this change, I see a reduction in memory allocated during RazorProjectEngine.ProcessDesignTime of 1.4%.