-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Remove some low hanging allocations #35397
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
Conversation
|
|
||
| protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) | ||
| { | ||
| if (FileKinds.IsComponent(codeDocument.GetFileKind())) |
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.
Are there other passes we can apply this heuristic on? E.g. ModelExpressionPass.
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.
Yeah, it does look like we could do more here. This one popped up when I was debugging / profiling.
* [x] In the ordinary case, diagnostics aren't produced by builders. The current pattern results in allocating a HashSet and an empty array for this case. Removing some of these allocations * [x] ViewComponentTagHelperPass does not need to operate on .razor files, but does some unnecessary work. We can avoid it
6e06b1f to
1ff0978
Compare
|
|
||
| internal static bool IsInvalidNonWhitespaceHtmlCharacters(char testChar) | ||
| { | ||
| foreach (var c in InvalidNonWhitespaceHtmlCharacters) |
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.
Does this not allocate an enumerator? Wondering why not a for loop is all 😄
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.
The compiler optimizes a foreach for arrays - https://sharplab.io/#v2:CYLg1APgAgTAjAWAFBQMwAJboMLoN7LpGYZQAs6AsgBQCU+hxTAbgIYBO6H7rAnugF50AOwCmAdwDaAXXzoA5K3kAaBQCMVCgMbz0AXwDcjJkWMmA9OfQBVAM4BLYQHN0AMwD27Uay0ALdAA27u4ADmZMAGKeAKI+vtTcfLRGSCbE4cSWNg7Obp6BwWGpaehR7AnsPLzJGabFRHpmZuSlMXHUfhwyXJVJZgT1Jh5ecejUbJxa6I49VbS1DIMlOO7Ctu4BogB0AOrs9gAuoh01S8SNgxdMzRRlHb5dsonV/QvDYxPTgugADAZfAB5ZnwtgAZUTOA6+f72MBgeZnIgDZZMbCrdabXb7I4VKqSezSU7LK7nZB6IA===
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.
oh wow, so the compiler special cases arrays or something?
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.
the compiler special cases arrays
It's not dictated by the language specifications, but as an optional optimization .NET's C# compiler (Roslyn) special cases (single dimensional) arrays, and strings so code equivalent to a for-loop is emitted.
and an empty array for this case. Removing some of these allocations