UriHelper.BuildAbsolute: opportunity for performance improvement #28905
Labels
area-hosting
Includes Hosting
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
Milestone
Summary
UriHelper.BuildAbsolute
creates an intermediary string for the combined path that is used only for concatenating with the other components to create the final URL.It also uses a non-pooled
StringBuilder
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 use in hot paths like redirect and rewrite rules.
Detailed design
StringBuilder_WithoutCombinedPathGeneration
Just by not generating the intermediary
combinePath
, there are memory usage improvements in the when the number of components is highier. There are also time improvements in those cases, but it's wrost in the other cases.String_Concat_WithArrayArgument
Given that the final URL is composed of more than 4 parts, the use of
string.Concat
incurs in an array allocation.But it still always performs better in terms of time and memory usage that using a
StringBuilder
.String_Create
string.Create
excels here in comparison to all the other options. It was created exactly for these use cases.Benchmarks
Code
The text was updated successfully, but these errors were encountered: