Reduce allocations in DefaultTagHelperTargetExtension.WriteTagHelperProperty#12361
Conversation
…roperty This method was building up strings via calls to GetPropertyAccessor to just write them into the code writer. Instead, we can just write the string components into the code writer directly, avoiding string concats that were about 0.4% of total allocations during typing in the RazorEditingTests.ScrollingAndTypingInCohosting speedometer test.
DustinCampbell
left a comment
There was a problem hiding this comment.
Note that CodeWriter.Write(...) has an overload that takes an interpolated string handler that can take lots of different values, including ReadOnlyMemory<char>. I added a few suggestions, but I'm sure you can find a lot more here to clean up and improve.
| } | ||
|
|
||
| return propertyAccessor; | ||
| return writer; |
There was a problem hiding this comment.
Not sure if write has a position property that could be used for it, but might be worth adding a Debug.Assert here to ensure that the method has written the same number of characters as GetPropertyAccessorLength returns, just to ensure nothing accidentally gets the two methods out of sync.
There was a problem hiding this comment.
I don't think that would work, as the write method may add indentation at it's whim
Cleaned up the ones that stood out |
This method was building up strings via calls to GetPropertyAccessor to just write them into the code writer.
Instead, we can just write the string components into the code writer directly, avoiding string concats that were about 0.4% of total allocations during typing in the RazorEditingTests.ScrollingAndTypingInCohosting speedometer test.