UriHelper.GetDisplayUrl: opportunity for performance improvement #28906
Labels
area-networking
Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
design-proposal
This issue represents a design proposal for a different issue, linked in the description
feature-http-abstractions
Milestone
Notes:
Updated to .NET 8.0
Summary
UriHelper.GetDisplayUrl
uses a non-pooledStringBuilder
that is instantiated on every invocation. Although optimized in size, it is a heap allocation with an intermediary buffer.Motivation and goals
This method is frequently used in hot paths like redirect and rewrite rules.
From the benchmarks below, we can see that, compared to the current implementation using a
StringBuilder
with enough capacity, string interpolation is around 3 times better in terms of duration and around 4 times in memory used.String.Create
is even more performant.Benchmarks
StringBuilder
This benchmark uses the same implementation as
UriHelper.GetDisplayUrl
.String_Interpolation
This benchmark uses string interpolation to build the URL.
String_Create
This benchmark uses
String.Create
and spans to build the URL.Code
The text was updated successfully, but these errors were encountered: