Improve performance of `AspNetCoreResourceNameHelper.SimplifyRouteTemplate` by andrewlock · Pull Request #8170 · DataDog/dd-trace-dotnet

chatgpt-codex-connector[bot]

lucaspimentel

andrewlock added a commit that referenced this pull request

Feb 11, 2026
## Summary of changes

Makes `ValueStringBuilder` usable in .NET Core 3.1+, instead of just
.NET 6

## Reason for change

I want to use it in some aspnetcore improvements, but currently it's
only exposed in .NET 6

## Implementation details

Update the `#if`. Note that I originally made this available in _all_
TFMs, using our vendored spans, but benchmarking showed that this was
actively harmful compared to just using `StringBuilderCache`, so to
avoid incorrect use, just restricting it for now.

## Test coverage

Updated the tests to cover .NET Core 3.1 too.

## Other details

Part of a stack
https://datadoghq.atlassian.net/browse/LANGPLAT-842


- #8167 👈
- #8170

Base automatically changed from andrew/aspnetcore-perf/valuestringbuilder to master

February 11, 2026 10:42

lucaspimentel

andrewlock added a commit that referenced this pull request

Feb 18, 2026
## Summary of changes

A few minor improvements to the standard `AspNetCoreDiagnosticObserver`

## Reason for change

Looking into obvious perf improvements for ASP.NET Core, but only a few
minor things stood out (apart from related PRs like #8199 and #8203).

## Implementation details

- Reduce size of MVC tags object by not deriving from `WebTags` (we
never set those tags anyway)
- Delay creating spanlinks collection if we don't need it
- HttpRoute always matches AspNetCoreRoute, so can make it readonly

## Test coverage

Covered by existing tests, benchmarks show (tiny) allocation gains

## Other details


Relates to https://datadoghq.atlassian.net/browse/LANGPLAT-842

Related PRs:
- #8167
- #8170
- #8180
- #8196
- #8199
- #8203

@andrewlock

@andrewlock

@andrewlock

@andrewlock

@andrewlock

@andrewlock

Add tests for both implementations, to document existing behaviour

@andrewlock

@andrewlock andrewlock deleted the andrew/aspnetcore-perf/route-templates branch

February 18, 2026 11:53

andrewlock added a commit that referenced this pull request

Feb 18, 2026
…tern` (#8180)

## Summary of changes

Switches to using `ValueStringBuilder` and other minor perf improvements

## Reason for change

Same as #8170, we want to improve performance where we can.
Unfortunately, we can't easily avoid the enumeration allocation like we
did in that PR, so most of the benefits here are simply from using
`ValueStringBuilder` and other minor changes.

## Implementation details

Incorporated various changes based on the `SimplifyRoutePattern` that we
use in the single-span aspnetcore observer and the changes made in
#8170. The gains aren't as high here, because we can't reduce
enumeration allocation.

## Test coverage

Covered by existing tests.

Ran benchmarks using the values. In general, there's a slight regression
in duration for an improvement in Alloc Ratio. It's not very consistent
though, particularly in <.NET Core 3.1. I think it's probably still
worth the change, but open to thoughts


| Method | Runtime | Has Defaults | Expand Templates | Mean | Allocated
| Alloc Ratio |
| -------- | ------------- | ------------ | ---------------- | --------:
| --------: | ----------: |
| Original | .NET 10.0 | False | False | 6.605 us | 6.51 KB | 1.00 |
| Updated | .NET 10.0 | False | False | 8.559 us | 4.8 KB | 0.74 |
| Original | .NET 6.0 | False | False | 11.466 us | 6.51 KB | 1.00 |
| Updated | .NET 6.0 | False | False | 11.654 us | 4.8 KB | 0.74 |
| Original | .NET Core 3.1 | False | False | 13.808 us | 6.51 KB | 1.00
|
| Updated | .NET Core 3.1 | False | False | 15.266 us | 4.8 KB | 0.74 |
| Original | .NET Core 3.0 | False | False | 13.962 us | 6.51 KB | 1.00
|
| Updated | .NET Core 3.0 | False | False | 19.757 us | 6.51 KB | 1.00 |
| | | | | | | |
| Original | .NET 10.0 | False | True | 6.453 us | 6.2 KB | 0.99 |
| Updated | .NET 10.0 | False | True | 8.116 us | 4.65 KB | 0.75 |
| Original | .NET 6.0 | False | True | 11.121 us | 6.23 KB | 1.00 |
| Updated | .NET 6.0 | False | True | 11.375 us | 4.65 KB | 0.75 |
| Original | .NET Core 3.1 | False | True | 14.075 us | 6.23 KB | 1.00 |
| Updated | .NET Core 3.1 | False | True | 15.000 us | 4.65 KB | 0.75 |
| Original | .NET Core 3.0 | False | True | 14.027 us | 6.23 KB | 1.00 |
| Updated | .NET Core 3.0 | False | True | 13.687 us | 6.2 KB | 0.99 |
| | | | | | | |
| Original | .NET 10.0 | True | False | 6.348 us | 6.51 KB | 1.00 |
| Updated | .NET 10.0 | True | False | 8.310 us | 4.8 KB | 0.74 |
| Original | .NET 6.0 | True | False | 11.082 us | 6.51 KB | 1.00 |
| Updated | .NET 6.0 | True | False | 11.406 us | 4.8 KB | 0.74 |
| Original | .NET Core 3.1 | True | False | 9.853 us | 6.51 KB | 1.00 |
| Updated | .NET Core 3.1 | True | False | 10.865 us | 4.8 KB | 0.74 |
| Original | .NET Core 3.0 | True | False | 14.879 us | 6.51 KB | 1.00 |
| Updated | .NET Core 3.0 | True | False | 10.221 us | 6.51 KB | 1.00 |
| | | | | | | |
| Original | .NET 10.0 | True | True | 4.002 us | 6.2 KB | 0.99 |
| Updated | .NET 10.0 | True | True | 5.685 us | 4.65 KB | 0.75 |
| Original | .NET 6.0 | True | True | 7.964 us | 6.23 KB | 1.00 |
| Updated | .NET 6.0 | True | True | 8.385 us | 4.65 KB | 0.75 |
| Original | .NET Core 3.1 | True | True | 13.949 us | 6.23 KB | 1.00 |
| Updated | .NET Core 3.1 | True | True | 15.370 us | 4.65 KB | 0.75 |
| Original | .NET Core 3.0 | True | True | 10.116 us | 6.23 KB | 1.00 |
| Updated | .NET Core 3.0 | True | True | 10.241 us | 6.2 KB | 0.99 |


## Other details
Part of a stack
https://datadoghq.atlassian.net/browse/LANGPLAT-842

- #8167
- #8170
- #8180 👈