Skip to content

Create a more optimized AspNetCoreResourceNameHelper#7966

Merged
andrewlock merged 2 commits intomasterfrom
andrew/single-span/5-resource-name
Jan 13, 2026
Merged

Create a more optimized AspNetCoreResourceNameHelper#7966
andrewlock merged 2 commits intomasterfrom
andrew/single-span/5-resource-name

Conversation

@andrewlock
Copy link
Member

@andrewlock andrewlock commented Dec 17, 2025

Summary of changes

Creates an optimized version of AspNetCoreResourceNameHelper for use by the single-span Diagnostic observer.

Reason for change

We have the opportunity for a variety of optimizations thanks to not creating the MVC span, and the fact that we're .NET 6+. We could potentially include some or all of these optimizations in the existing observer path, but for safety/simplicity I'd rather keep it isolated for now, and we can look at expanding it more broadly later

Implementation details

  • Use the ValueStringBuilder to build a resource name
  • Don't pre-grab MVC route values, wait to see if we have route params from them first
  • Write directly into the builder as ToLowerInvariant, instead of doing an extra ToLower() at the end

Test coverage

Added unit tests that use the existing data for the other implementations, to confirm it's identical. It's also covered indirectly by the integration tests

Other details

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

Part of a stack

@datadog-official
Copy link

datadog-official bot commented Dec 17, 2025

⚠️ Tests

Fix all issues with Cursor

⚠️ Warnings

❄️ 43 New flaky tests detected

SubmitsOtlpLogs from Datadog.Trace.ClrProfiler.IntegrationTests.OpenTelemetrySdkTests (Datadog) (Fix with Cursor)
Expected logsData not to be empty.
TestIastCommandInjectionRequest from Datadog.Trace.Security.IntegrationTests.Iast.AspNetCore5IastTestsFullSamplingIastEnabled (Datadog) (Fix with Cursor)
Results do not match.
Differences:
Received: Iast.CommandInjection.AspNetCore5.IastEnabled.received.txt
Verified: Iast.CommandInjection.AspNetCore5.IastEnabled.verified.txt
Compare Result:
- [
+ []
-   {
-     TraceId: Id_1,
-     SpanId: Id_2,
...
TestIastCookiesRequest from Datadog.Trace.Security.IntegrationTests.Iast.AspNetCore5IastTestsFullSamplingIastEnabled (Datadog) (Fix with Cursor)
Results do not match.
Differences:
Received: Iast.AspNetCore5.enableIast=True.path =_Iast_AllVulnerabilitiesCookie.received.txt
Verified: Iast.AspNetCore5.enableIast=True.path =_Iast_AllVulnerabilitiesCookie.verified.txt
Compare Result:
- [
+ []
-   {
-     TraceId: Id_1,
-     SpanId: Id_2,
...
View all

ℹ️ Info

🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2ce366f | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@andrewlock andrewlock force-pushed the andrew/single-span/5-resource-name branch from c2c2b8c to 37760e4 Compare December 18, 2025 09:23
@andrewlock andrewlock requested review from a team as code owners December 18, 2025 09:23
@andrewlock andrewlock force-pushed the andrew/single-span/3-observer branch from 5e4ff26 to bdd3a0f Compare December 18, 2025 09:23
@dd-trace-dotnet-ci-bot
Copy link

dd-trace-dotnet-ci-bot bot commented Dec 18, 2025

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (7966) and master.

✅ No regressions detected - check the details below

Full Metrics Comparison

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration74.14 ± (74.06 - 74.40) ms77.87 ± (77.78 - 78.23) ms+5.0%✅⬆️
.NET Framework 4.8 - Bailout
duration78.00 ± (77.82 - 78.21) ms82.38 ± (82.24 - 82.63) ms+5.6%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1042.80 ± (1044.78 - 1051.91) ms1086.73 ± (1087.24 - 1094.87) ms+4.2%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms22.79 ± (22.74 - 22.84) ms23.86 ± (23.80 - 23.91) ms+4.7%✅⬆️
process.time_to_main_ms85.19 ± (84.99 - 85.40) ms89.95 ± (89.71 - 90.19) ms+5.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.92 ± (10.92 - 10.92) MB10.93 ± (10.93 - 10.94) MB+0.1%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms22.67 ± (22.62 - 22.72) ms23.56 ± (23.50 - 23.62) ms+3.9%✅⬆️
process.time_to_main_ms86.35 ± (86.11 - 86.58) ms90.99 ± (90.76 - 91.22) ms+5.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.95 ± (10.95 - 10.96) MB10.94 ± (10.94 - 10.95) MB-0.1%
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms248.27 ± (244.43 - 252.10) ms245.38 ± (240.30 - 250.46) ms-1.2%
process.time_to_main_ms488.56 ± (487.88 - 489.24) ms514.51 ± (513.32 - 515.69) ms+5.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.30 ± (48.27 - 48.32) MB48.28 ± (48.25 - 48.32) MB-0.0%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-1.1%
.NET 6 - Baseline
process.internal_duration_ms21.46 ± (21.43 - 21.50) ms22.30 ± (22.25 - 22.35) ms+3.9%✅⬆️
process.time_to_main_ms73.16 ± (73.02 - 73.31) ms77.93 ± (77.74 - 78.12) ms+6.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.64 ± (10.63 - 10.64) MB10.64 ± (10.64 - 10.65) MB+0.1%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms21.49 ± (21.43 - 21.54) ms22.06 ± (22.01 - 22.11) ms+2.6%✅⬆️
process.time_to_main_ms74.60 ± (74.42 - 74.79) ms78.96 ± (78.77 - 79.15) ms+5.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.72 ± (10.71 - 10.73) MB10.74 ± (10.74 - 10.75) MB+0.2%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms242.37 ± (238.68 - 246.07) ms249.51 ± (245.56 - 253.45) ms+2.9%✅⬆️
process.time_to_main_ms461.90 ± (461.35 - 462.45) ms482.59 ± (481.87 - 483.31) ms+4.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.18 ± (49.15 - 49.20) MB49.02 ± (48.99 - 49.04) MB-0.3%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.1%
.NET 8 - Baseline
process.internal_duration_ms19.46 ± (19.42 - 19.49) ms20.44 ± (20.40 - 20.49) ms+5.1%✅⬆️
process.time_to_main_ms72.48 ± (72.33 - 72.62) ms77.01 ± (76.83 - 77.18) ms+6.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.67 ± (7.66 - 7.68) MB7.70 ± (7.69 - 7.70) MB+0.4%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.53 ± (19.49 - 19.58) ms20.28 ± (20.22 - 20.35) ms+3.8%✅⬆️
process.time_to_main_ms73.97 ± (73.81 - 74.12) ms77.63 ± (77.46 - 77.80) ms+5.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.78 ± (7.77 - 7.79) MB7.73 ± (7.72 - 7.74) MB-0.6%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms187.00 ± (186.26 - 187.74) ms198.10 ± (197.38 - 198.81) ms+5.9%✅⬆️
process.time_to_main_ms447.51 ± (446.84 - 448.18) ms470.81 ± (470.00 - 471.63) ms+5.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.63 ± (36.59 - 36.66) MB36.97 ± (36.94 - 37.00) MB+0.9%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)+0.0%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration192.82 ± (192.76 - 193.76) ms193.85 ± (193.90 - 194.60) ms+0.5%✅⬆️
.NET Framework 4.8 - Bailout
duration196.46 ± (196.43 - 197.21) ms196.87 ± (196.84 - 197.26) ms+0.2%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1114.07 ± (1117.72 - 1127.18) ms1132.04 ± (1130.66 - 1144.56) ms+1.6%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms187.24 ± (186.88 - 187.60) ms189.05 ± (188.62 - 189.47) ms+1.0%✅⬆️
process.time_to_main_ms80.15 ± (79.93 - 80.36) ms81.25 ± (80.98 - 81.51) ms+1.4%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.07 ± (16.03 - 16.10) MB16.20 ± (16.17 - 16.23) MB+0.8%✅⬆️
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (20 - 20)+0.3%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms186.63 ± (186.34 - 186.93) ms187.81 ± (187.48 - 188.14) ms+0.6%✅⬆️
process.time_to_main_ms81.45 ± (81.33 - 81.57) ms82.14 ± (82.01 - 82.27) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.17 ± (16.14 - 16.20) MB16.19 ± (16.15 - 16.22) MB+0.1%✅⬆️
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)+0.1%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms435.78 ± (433.44 - 438.11) ms433.89 ± (431.18 - 436.61) ms-0.4%
process.time_to_main_ms468.83 ± (468.19 - 469.47) ms471.78 ± (471.17 - 472.40) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.63 ± (58.52 - 58.74) MB58.67 ± (58.54 - 58.80) MB+0.1%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 30)29 ± (29 - 29)-0.1%
.NET 6 - Baseline
process.internal_duration_ms192.43 ± (192.07 - 192.80) ms193.43 ± (193.00 - 193.85) ms+0.5%✅⬆️
process.time_to_main_ms69.45 ± (69.29 - 69.60) ms70.43 ± (70.23 - 70.62) ms+1.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.08 ± (15.95 - 16.22) MB16.33 ± (16.24 - 16.42) MB+1.5%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)19 ± (19 - 19)+4.0%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms190.75 ± (190.43 - 191.06) ms192.64 ± (192.22 - 193.05) ms+1.0%✅⬆️
process.time_to_main_ms70.21 ± (70.13 - 70.30) ms71.31 ± (71.16 - 71.45) ms+1.6%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.03 ± (15.87 - 16.19) MB16.10 ± (15.95 - 16.25) MB+0.4%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)20 ± (19 - 20)+2.9%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms450.54 ± (447.69 - 453.40) ms454.37 ± (452.69 - 456.04) ms+0.8%✅⬆️
process.time_to_main_ms448.51 ± (447.93 - 449.09) ms451.19 ± (450.67 - 451.71) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed58.81 ± (58.67 - 58.96) MB58.64 ± (58.54 - 58.74) MB-0.3%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.0%
.NET 8 - Baseline
process.internal_duration_ms191.09 ± (190.68 - 191.50) ms191.08 ± (190.75 - 191.40) ms-0.0%
process.time_to_main_ms69.34 ± (69.14 - 69.55) ms69.91 ± (69.69 - 70.14) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.74 ± (11.71 - 11.77) MB11.71 ± (11.68 - 11.73) MB-0.3%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)+0.4%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms189.92 ± (189.56 - 190.28) ms191.05 ± (190.66 - 191.45) ms+0.6%✅⬆️
process.time_to_main_ms70.33 ± (70.22 - 70.45) ms70.84 ± (70.70 - 70.98) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.78 ± (11.75 - 11.81) MB11.75 ± (11.73 - 11.78) MB-0.2%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.2%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms363.43 ± (361.73 - 365.14) ms364.21 ± (362.68 - 365.74) ms+0.2%✅⬆️
process.time_to_main_ms431.89 ± (431.10 - 432.68) ms434.56 ± (433.86 - 435.25) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.21 ± (48.17 - 48.25) MB48.26 ± (48.22 - 48.30) MB+0.1%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.3%
Comparison explanation

Execution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

Duration charts
FakeDbCommand (.NET Framework 4.8)
gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7966) - mean (78ms)  : 75, 81
    master - mean (74ms)  : 72, 77

    section Bailout
    This PR (7966) - mean (82ms)  : 80, 85
    master - mean (78ms)  : 76, 80

    section CallTarget+Inlining+NGEN
    This PR (7966) - mean (1,091ms)  : 1037, 1145
    master - mean (1,048ms)  : 996, 1100

Loading
FakeDbCommand (.NET Core 3.1)
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7966) - mean (121ms)  : 116, 127
    master - mean (115ms)  : 111, 118

    section Bailout
    This PR (7966) - mean (122ms)  : 118, 125
    master - mean (116ms)  : 113, 119

    section CallTarget+Inlining+NGEN
    This PR (7966) - mean (797ms)  : 740, 855
    master - mean (773ms)  : 715, 832

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7966) - mean (107ms)  : 102, 112
    master - mean (101ms)  : 98, 104

    section Bailout
    This PR (7966) - mean (108ms)  : 105, 111
    master - mean (102ms)  : 100, 105

    section CallTarget+Inlining+NGEN
    This PR (7966) - mean (760ms)  : 679, 840
    master - mean (737ms)  : 670, 805

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7966) - mean (105ms)  : 102, 109
    master - mean (100ms)  : 97, 102

    section Bailout
    This PR (7966) - mean (106ms)  : 103, 108
    master - mean (101ms)  : 99, 103

    section CallTarget+Inlining+NGEN
    This PR (7966) - mean (706ms)  : crit, 679, 734
    master - mean (668ms)  : 647, 689

Loading
HttpMessageHandler (.NET Framework 4.8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7966) - mean (194ms)  : 191, 198
    master - mean (193ms)  : 188, 198

    section Bailout
    This PR (7966) - mean (197ms)  : 195, 199
    master - mean (197ms)  : 193, 201

    section CallTarget+Inlining+NGEN
    This PR (7966) - mean (1,138ms)  : 1066, 1209
    master - mean (1,122ms)  : 1054, 1191

Loading
HttpMessageHandler (.NET Core 3.1)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7966) - mean (279ms)  : 272, 287
    master - mean (276ms)  : 269, 282

    section Bailout
    This PR (7966) - mean (278ms)  : 274, 282
    master - mean (276ms)  : 272, 280

    section CallTarget+Inlining+NGEN
    This PR (7966) - mean (936ms)  : 895, 977
    master - mean (931ms)  : 890, 972

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7966) - mean (272ms)  : 266, 279
    master - mean (270ms)  : 264, 276

    section Bailout
    This PR (7966) - mean (272ms)  : 267, 278
    master - mean (269ms)  : 266, 272

    section CallTarget+Inlining+NGEN
    This PR (7966) - mean (935ms)  : 901, 969
    master - mean (929ms)  : 884, 973

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7966) - mean (271ms)  : 266, 276
    master - mean (270ms)  : 264, 276

    section Bailout
    This PR (7966) - mean (271ms)  : 266, 277
    master - mean (269ms)  : 265, 273

    section CallTarget+Inlining+NGEN
    This PR (7966) - mean (831ms)  : 813, 849
    master - mean (827ms)  : 808, 845

Loading

@andrewlock andrewlock force-pushed the andrew/single-span/5-resource-name branch from 37760e4 to 65dcd0e Compare December 18, 2025 14:09
@andrewlock andrewlock requested review from a team as code owners December 18, 2025 14:09
@andrewlock andrewlock force-pushed the andrew/single-span/3-observer branch from bdd3a0f to 88205c8 Compare December 18, 2025 14:09
Copy link
Collaborator

@NachoEchevarria NachoEchevarria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

bool expandRouteParameters)
{
var sb = routePattern.RawText?.Length < 512
? new ValueStringBuilder(stackalloc char[512])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

andrewlock added a commit that referenced this pull request Dec 23, 2025
## Summary of changes

Adds a `ValueStringBuilder` implementation, based on the one used
internally in the .NET runtime

## Reason for change

- We can stackalloc the `Span<char>`
- It's a bit faster than our existing `StringBuilderCache`
implementation, and in some places that matters.

## Implementation details

- Made in .NET 6 only for simplicity. We _could_ expose it earlier, but
I wanted this for the updated aspnetcore integration, so .NET6+ only for
now is good enough
- It's not without risks in its usage, so we have to be careful about
things like passing it around (i.e. avoid doing that completely, for
safety)
- Uses an array pool backed implementation (again, built into .NET 6)

## Test coverage

Imported the unit tests from the runtime too

## Other details

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

Part of a stack

- #7962 👈
- #7963
- #7964
- #7966
- #7965
@andrewlock andrewlock force-pushed the andrew/single-span/5-resource-name branch from 65dcd0e to 303a7ac Compare December 23, 2025 12:17
@andrewlock andrewlock requested review from a team as code owners December 23, 2025 12:17
@andrewlock andrewlock force-pushed the andrew/single-span/3-observer branch from 00fe314 to e8369e2 Compare December 23, 2025 12:17
@pr-commenter
Copy link

pr-commenter bot commented Dec 23, 2025

Benchmarks

Benchmark execution time: 2026-01-13 15:33:43

Comparing candidate commit 2ce366f in PR branch andrew/single-span/5-resource-name with baseline commit e764036 in branch master.

Found 15 performance improvements and 3 performance regressions! Performance is the same for 156 metrics, 12 unstable metrics.

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net6.0

  • 🟩 throughput [+6684.277op/s; +8746.837op/s] or [+6.202%; +8.115%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • 🟩 execution_time [-80.534ms; -80.438ms] or [-39.502%; -39.455%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 execution_time [+89.227ms; +89.346ms] or [+80.561%; +80.668%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1

  • 🟥 execution_time [+16.871ms; +18.774ms] or [+9.216%; +10.256%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1

  • 🟩 execution_time [-52.860µs; -25.288µs] or [-14.465%; -6.920%]
  • 🟩 throughput [+190.583op/s; +386.422op/s] or [+6.848%; +13.885%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟩 execution_time [-56.909ms; -51.027ms] or [-22.334%; -20.026%]
  • 🟩 throughput [+239.364op/s; +267.003op/s] or [+25.405%; +28.339%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0

  • 🟩 execution_time [-111.366µs; -107.248µs] or [-7.448%; -7.173%]
  • 🟩 throughput [+51.778op/s; +53.725op/s] or [+7.742%; +8.033%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1

  • 🟩 execution_time [-920.950µs; -659.573µs] or [-33.250%; -23.813%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0

  • 🟩 execution_time [-94.439µs; -90.601µs] or [-8.499%; -8.153%]
  • 🟩 throughput [+80.059op/s; +83.404op/s] or [+8.896%; +9.268%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net6.0

  • 🟥 execution_time [+12.719ms; +15.445ms] or [+6.445%; +7.826%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net6.0

  • 🟩 execution_time [-834.736µs; -763.131µs] or [-61.548%; -56.268%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0

  • 🟩 execution_time [-7.506µs; -3.606µs] or [-15.019%; -7.214%]
  • 🟩 throughput [+1368.989op/s; +2808.931op/s] or [+6.675%; +13.695%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes netcoreapp3.1

  • 🟩 execution_time [-16.807ms; -11.471ms] or [-7.915%; -5.402%]

@andrewlock andrewlock force-pushed the andrew/single-span/5-resource-name branch from 303a7ac to 8a6357a Compare December 23, 2025 14:50
@andrewlock andrewlock force-pushed the andrew/single-span/3-observer branch from e8369e2 to bb0fb1b Compare December 23, 2025 14:50
andrewlock added a commit that referenced this pull request Dec 24, 2025
## Summary of changes

Small perf tweaks for existing `AspNetCoreDiagnosticObserver`

## Reason for change

While experimenting with single span observer, noticed some (safe)
tweaks we could make to the existing implementation. There are some
other improvements we could make as well, but those are a little
riskier, so may be best to delay them.

## Implementation details

- Use `HttpContext.Items[string]` instead of
`HttpContext.Features.Get<T>` as it's a bit faster
- Make `Tracer`/`Security`/`Iast` inputs readonly, instead of using a
null-coalesce with every access
- Move check outside of `AddHeaderTagsToSpan` given common case is to
avoid the function call

## Test coverage

Covered by existing tests

## Other details

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

Part of a stack


- #7962
- #7963 👈
- #7964
- #7966
- #7965
@andrewlock andrewlock force-pushed the andrew/single-span/5-resource-name branch from 8a6357a to 4fd083f Compare December 24, 2025 13:29
@andrewlock andrewlock force-pushed the andrew/single-span/3-observer branch from bb0fb1b to a356866 Compare December 24, 2025 13:29
@andrewlock andrewlock force-pushed the andrew/single-span/5-resource-name branch from 4fd083f to 5d97960 Compare December 24, 2025 14:00
@andrewlock andrewlock force-pushed the andrew/single-span/3-observer branch from a356866 to 04d208f Compare December 24, 2025 14:00
@andrewlock andrewlock force-pushed the andrew/single-span/5-resource-name branch from 5d97960 to 67ea0dd Compare January 5, 2026 08:19
@andrewlock andrewlock force-pushed the andrew/single-span/3-observer branch from 04d208f to de692e8 Compare January 5, 2026 08:19
andrewlock added a commit that referenced this pull request Jan 13, 2026
## Summary of changes

Adds a new `DD_TRACE_SINGLE_SPAN_ASPNETCORE_ENABLED` in which we omit
the MVC span

## Reason for change

- Addresses #4093 and partially #1147
- Omitting the MVC span has perf and some usability benefits in some
cases (See issues above). It _does_ mean a certain amount of less
information, particularly in pipeline re-execution scenarios

## Implementation details

- Add a new, disabled by default,
`DD_TRACE_SINGLE_SPAN_ASPNETCORE_ENABLED` for opting in to the new
behaviour.
- .NET 6+ only for various reasons
- Cloned the original observer, deleted everything related to the MVC
span, and then optimized further based on .NET 6+ and other improvements
we can make

## Test coverage

- Added in-process "integration" tests for the observer (more like unit
tests), which mirror the exisitng.
- Added "full" sample-based integration tests for basically all
scenarios we currently test (IIS in process/out of process / MVC /
minimal APIs / proxy spans etc)
- Added snapshots by copying existing, and then updating, so if you look
at the final commit, you can see the diff, which is basically just
"delete the child span"

## Other details

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

Part of a stack



- #7962
- #7963
- #7964 👈
- #7966
- #7965

I experimented with some other perf improvements, but they didn't
provide a significant improvement, so I reverted:
- Caching the resource name by saving it into the `IEndpointMetadata`
collection. The work to do that was too much, and you _can't_ cache in
some cases anyway so not worth it
- Splitting `WebTags` out to remove the IP headers unless we need them.
They're disabled by default, so it just increase the size of the tags
object, but wasn't a big enough improvement to make the complexity worth
it.
- Tried pooling the `RequestTrackingFeature` objects. This one _may_
actually be worth exploring again later, but I didn't see any
improvement in my testing, as they're just not very big and only last 1
request.

---------

Co-authored-by: Lucas Pimentel <lucas.pimentel@datadoghq.com>
Base automatically changed from andrew/single-span/3-observer to master January 13, 2026 14:47
@andrewlock andrewlock force-pushed the andrew/single-span/5-resource-name branch from 67ea0dd to 2ce366f Compare January 13, 2026 14:51
@andrewlock andrewlock enabled auto-merge (squash) January 13, 2026 15:49
@andrewlock andrewlock merged commit 3263efa into master Jan 13, 2026
150 of 151 checks passed
@andrewlock andrewlock deleted the andrew/single-span/5-resource-name branch January 13, 2026 18:28
@github-actions github-actions bot added this to the vNext-v3 milestone Jan 13, 2026
andrewlock added a commit that referenced this pull request Jan 13, 2026
…7965)

## Summary of changes

Adds a micro and macro benchmark for the new observer

## Reason for change

Want to verify that it has performance benefits

## Implementation details

- Added new scenario for macro
- Duplicated existing scenario for micro and run. I would like to have
had these as the same methods, but the "global" nature of diagnostic
observers makes this difficult I think.

## Test coverage

I'll manually trigger a run of the macro

## Other details

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

Part of a stack



- #7962
- #7963
- #7964
- #7966
- #7965 👈
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:integrations type:performance Performance, speed, latency, resource usage (CPU, memory)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants