Optimize temporary string usage when DefaultInterpolatedStringHandler is used #77597
Labels
Area-Compilers
Code Gen Quality
Room for improvement in the quality of the compiler's generated code
Version Used:
.NET 10
Steps to Reproduce:
Today, the compiler generates code using
DefaultInterpolatedStringHandler
for various scenarios, I don't know all the places it's used and whether they might benefit from updates, so I'll focus on the one I do know.Given the following simplified code
The compiler generates:
The issue is that
defaultInterpolatedStringHandler.ToStringAndClear()
allocates a string just to do a string comparison, which should be allocation free if we could access the underlyingReadOnlySpan<char>
.With dotnet/runtime#112171 being merged, we now have access the the underlying
ReadOnlySpan<char>
and a way to clear the pooled memory when we're done with the string handler.It would be nice if the compiler could now generate the allocation free code:
Resulting in free perf for all!
The text was updated successfully, but these errors were encountered: