Skip to content

Reduce allocation in ExposureApi by serializing to stream#8051

Merged
andrewlock merged 2 commits intomasterfrom
andrew/update-ff-api
Jan 15, 2026
Merged

Reduce allocation in ExposureApi by serializing to stream#8051
andrewlock merged 2 commits intomasterfrom
andrew/update-ff-api

Conversation

@andrewlock
Copy link
Member

@andrewlock andrewlock commented Jan 13, 2026

Summary of changes

Use the new PostAsJsonAsync API to avoid serializing to string and byte array locally

Reason for change

We recently added support for PostAsJsonAsync in #8017, and this is a good example where we can easily swap it in in the new Exposures API used by FFE: #7896

Implementation details

Just updated to use the new APIs. A couple of points to notice:

  • This doesn't enable gzip. If the endpoint supports it, we should probably enable that, but would need testing
  • This changes the serialization settings, by using SerializationHelpers.DefaultJsonSettings, which omits serializing null members, and uses snake-case serialization, instead of the PascalCase we have currently
    • However, looking at the spec, I'm pretty sure we're not compliant today, and what we're changing to is correct
    • Which suggests we're missing tests...

Test coverage

This should be covered by existing tests... and if it's not, then we need to add those tests 😄

@andrewlock andrewlock requested a review from a team as a code owner January 13, 2026 10:34
@andrewlock andrewlock added type:performance Performance, speed, latency, resource usage (CPU, memory) feature_flags labels Jan 13, 2026
@github-actions github-actions bot added the area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) label Jan 13, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8826bd8ef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@pr-commenter
Copy link

pr-commenter bot commented Jan 13, 2026

Benchmarks

Benchmark execution time: 2026-01-13 12:00:58

Comparing candidate commit c4cd4b3 in PR branch andrew/update-ff-api with baseline commit 9cc9f31 in branch master.

Found 4 performance improvements and 4 performance regressions! Performance is the same for 168 metrics, 10 unstable metrics.

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

  • 🟩 execution_time [-87.423ms; -87.192ms] or [-44.518%; -44.400%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1

  • 🟩 throughput [+35170.828op/s; +52265.829op/s] or [+5.104%; +7.585%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟩 throughput [+158.361op/s; +180.635op/s] or [+15.541%; +17.726%]

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

  • 🟥 throughput [-122.313op/s; -81.836op/s] or [-8.091%; -5.413%]
  • 🟩 execution_time [-34.291ms; -29.317ms] or [-17.977%; -15.370%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net6.0

  • 🟥 execution_time [+15.069ms; +19.001ms] or [+7.547%; +9.516%]

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

  • 🟥 execution_time [+11.321ms; +17.152ms] or [+5.753%; +8.715%]

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

  • 🟥 execution_time [+10.101ms; +15.794ms] or [+5.165%; +8.076%]

Copy link
Contributor

@daniel-romano-DD daniel-romano-DD left a comment

Choose a reason for hiding this comment

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

Thanks a lot

@datadog-official
Copy link

datadog-official bot commented Jan 13, 2026

⚠️ Tests

Fix all issues with Cursor

⚠️ Warnings

❄️ 1 New flaky test detected

WhenSupported_WritesAStatsPointAfterDelay from Datadog.Trace.Tests.DataStreamsMonitoring.DataStreamsWriterTests (Datadog) (Fix with Cursor)
Expected api.Sent to contain at least 1 item(s), but found 0: {empty}.

ℹ️ Info

🧪 All tests passed

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

@dd-trace-dotnet-ci-bot
Copy link

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8051) 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
duration68.24 ± (68.22 - 68.41) ms68.09 ± (68.11 - 68.32) ms-0.2%
.NET Framework 4.8 - Bailout
duration71.99 ± (71.86 - 72.12) ms71.98 ± (71.90 - 72.08) ms-0.0%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1002.90 ± (1004.14 - 1009.36) ms1001.55 ± (1003.68 - 1009.59) ms-0.1%
.NET Core 3.1 - Baseline
process.internal_duration_ms21.97 ± (21.94 - 22.00) ms21.94 ± (21.92 - 21.97) ms-0.1%
process.time_to_main_ms78.84 ± (78.67 - 79.02) ms78.67 ± (78.52 - 78.82) ms-0.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.91 ± (10.91 - 10.92) MB10.95 ± (10.94 - 10.95) MB+0.3%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms21.93 ± (21.90 - 21.95) ms21.82 ± (21.79 - 21.84) ms-0.5%
process.time_to_main_ms79.66 ± (79.57 - 79.75) ms79.94 ± (79.85 - 80.03) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.94 ± (10.94 - 10.95) MB10.95 ± (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_ms239.58 ± (235.60 - 243.56) ms243.24 ± (239.04 - 247.45) ms+1.5%✅⬆️
process.time_to_main_ms470.60 ± (470.15 - 471.05) ms474.65 ± (473.92 - 475.38) ms+0.9%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.27 ± (48.25 - 48.30) MB48.30 ± (48.28 - 48.32) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.2%
.NET 6 - Baseline
process.internal_duration_ms20.64 ± (20.61 - 20.67) ms20.81 ± (20.79 - 20.84) ms+0.8%✅⬆️
process.time_to_main_ms68.00 ± (67.87 - 68.14) ms69.79 ± (69.64 - 69.93) ms+2.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.61 ± (10.61 - 10.62) MB10.65 ± (10.64 - 10.65) MB+0.3%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.58 ± (20.55 - 20.61) ms20.73 ± (20.71 - 20.76) ms+0.7%✅⬆️
process.time_to_main_ms68.85 ± (68.78 - 68.91) ms70.60 ± (70.46 - 70.74) ms+2.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.71 ± (10.70 - 10.72) MB10.74 ± (10.74 - 10.75) MB+0.3%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms242.20 ± (239.84 - 244.56) ms238.15 ± (234.91 - 241.38) ms-1.7%
process.time_to_main_ms440.65 ± (440.22 - 441.08) ms444.87 ± (444.32 - 445.41) ms+1.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.88 ± (48.85 - 48.91) MB48.85 ± (48.81 - 48.88) MB-0.1%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms18.83 ± (18.79 - 18.86) ms19.07 ± (19.05 - 19.09) ms+1.3%✅⬆️
process.time_to_main_ms66.93 ± (66.82 - 67.03) ms69.81 ± (69.66 - 69.96) ms+4.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.64 ± (7.64 - 7.65) MB7.67 ± (7.67 - 7.68) MB+0.4%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.64 ± (18.62 - 18.66) ms19.23 ± (19.20 - 19.26) ms+3.2%✅⬆️
process.time_to_main_ms67.63 ± (67.58 - 67.68) ms71.02 ± (70.88 - 71.15) ms+5.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.75 ± (7.74 - 7.76) MB7.72 ± (7.71 - 7.73) MB-0.4%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms179.22 ± (178.08 - 180.36) ms184.43 ± (183.51 - 185.36) ms+2.9%✅⬆️
process.time_to_main_ms424.65 ± (424.13 - 425.18) ms435.75 ± (434.95 - 436.55) ms+2.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.38 ± (36.35 - 36.41) MB36.50 ± (36.47 - 36.53) MB+0.3%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)+0.6%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration192.33 ± (192.22 - 193.06) ms192.34 ± (192.38 - 193.32) ms+0.0%✅⬆️
.NET Framework 4.8 - Bailout
duration195.45 ± (195.48 - 196.11) ms196.39 ± (196.29 - 196.88) ms+0.5%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1118.79 ± (1125.01 - 1135.46) ms1110.13 ± (1109.67 - 1118.36) ms-0.8%
.NET Core 3.1 - Baseline
process.internal_duration_ms187.87 ± (187.50 - 188.24) ms188.15 ± (187.73 - 188.57) ms+0.2%✅⬆️
process.time_to_main_ms80.11 ± (79.91 - 80.31) ms80.48 ± (80.24 - 80.72) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.07 ± (16.05 - 16.10) MB16.12 ± (16.08 - 16.15) MB+0.3%✅⬆️
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (19 - 20)-0.2%
.NET Core 3.1 - Bailout
process.internal_duration_ms186.74 ± (186.42 - 187.05) ms186.62 ± (186.29 - 186.95) ms-0.1%
process.time_to_main_ms81.32 ± (81.17 - 81.47) ms81.49 ± (81.36 - 81.61) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.14 ± (16.11 - 16.17) MB16.24 ± (16.21 - 16.26) MB+0.6%✅⬆️
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)+0.1%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms425.88 ± (422.82 - 428.94) ms425.09 ± (422.12 - 428.05) ms-0.2%
process.time_to_main_ms472.62 ± (471.94 - 473.29) ms474.03 ± (473.48 - 474.59) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.76 ± (58.64 - 58.88) MB58.87 ± (58.76 - 58.99) MB+0.2%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 30)30 ± (29 - 30)+0.0%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms191.52 ± (191.20 - 191.83) ms191.85 ± (191.47 - 192.22) ms+0.2%✅⬆️
process.time_to_main_ms69.20 ± (69.04 - 69.37) ms69.23 ± (69.10 - 69.35) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.04 ± (15.91 - 16.18) MB16.18 ± (16.04 - 16.33) MB+0.9%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 19)+0.2%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms190.93 ± (190.63 - 191.23) ms191.04 ± (190.75 - 191.33) ms+0.1%✅⬆️
process.time_to_main_ms70.10 ± (70.00 - 70.21) ms70.39 ± (70.28 - 70.50) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.12 ± (15.99 - 16.25) MB16.28 ± (16.16 - 16.40) MB+1.0%✅⬆️
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (19 - 20)+0.8%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms452.82 ± (449.93 - 455.71) ms453.89 ± (451.56 - 456.22) ms+0.2%✅⬆️
process.time_to_main_ms445.06 ± (444.46 - 445.67) ms447.01 ± (446.47 - 447.56) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed58.45 ± (58.32 - 58.58) MB58.55 ± (58.44 - 58.67) MB+0.2%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.2%
.NET 8 - Baseline
process.internal_duration_ms193.64 ± (193.22 - 194.05) ms191.76 ± (191.36 - 192.16) ms-1.0%
process.time_to_main_ms70.98 ± (70.73 - 71.23) ms69.34 ± (69.17 - 69.51) ms-2.3%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.67 ± (11.65 - 11.70) MB11.74 ± (11.72 - 11.76) MB+0.5%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.2%
.NET 8 - Bailout
process.internal_duration_ms189.16 ± (188.85 - 189.47) ms189.96 ± (189.68 - 190.23) ms+0.4%✅⬆️
process.time_to_main_ms69.86 ± (69.74 - 69.97) ms70.43 ± (70.29 - 70.58) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.72 ± (11.65 - 11.79) MB11.80 ± (11.76 - 11.84) MB+0.6%✅⬆️
runtime.dotnet.threads.count19 ± (18 - 19)19 ± (19 - 19)+2.8%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms364.97 ± (363.53 - 366.40) ms365.01 ± (363.33 - 366.68) ms+0.0%✅⬆️
process.time_to_main_ms428.92 ± (428.30 - 429.55) ms429.45 ± (428.85 - 430.04) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.08 ± (48.05 - 48.11) MB48.08 ± (48.05 - 48.12) MB+0.0%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.2%
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 (8051) - mean (68ms)  : 67, 70
    master - mean (68ms)  : 67, 70

    section Bailout
    This PR (8051) - mean (72ms)  : 71, 73
    master - mean (72ms)  : 71, 73

    section CallTarget+Inlining+NGEN
    This PR (8051) - mean (1,007ms)  : 965, 1049
    master - mean (1,007ms)  : 970, 1044

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 (8051) - mean (106ms)  : 103, 108
    master - mean (106ms)  : 103, 109

    section Bailout
    This PR (8051) - mean (107ms)  : 106, 108
    master - mean (107ms)  : 106, 108

    section CallTarget+Inlining+NGEN
    This PR (8051) - mean (742ms)  : 671, 813
    master - mean (735ms)  : 681, 789

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8051) - mean (96ms)  : 92, 99
    master - mean (93ms)  : 91, 95

    section Bailout
    This PR (8051) - mean (97ms)  : 94, 99
    master - mean (94ms)  : 93, 95

    section CallTarget+Inlining+NGEN
    This PR (8051) - mean (707ms)  : 656, 758
    master - mean (708ms)  : 672, 745

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8051) - mean (96ms)  : 92, 99
    master - mean (92ms)  : 90, 94

    section Bailout
    This PR (8051) - mean (97ms)  : 95, 99
    master - mean (92ms)  : 91, 93

    section CallTarget+Inlining+NGEN
    This PR (8051) - mean (650ms)  : 630, 669
    master - mean (632ms)  : 619, 645

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 (8051) - mean (193ms)  : 188, 198
    master - mean (193ms)  : 189, 197

    section Bailout
    This PR (8051) - mean (197ms)  : 194, 199
    master - mean (196ms)  : 193, 199

    section CallTarget+Inlining+NGEN
    This PR (8051) - mean (1,114ms)  : 1063, 1165
    master - mean (1,130ms)  : 1049, 1211

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 (8051) - mean (277ms)  : 270, 284
    master - mean (276ms)  : 271, 281

    section Bailout
    This PR (8051) - mean (276ms)  : 272, 280
    master - mean (276ms)  : 273, 279

    section CallTarget+Inlining+NGEN
    This PR (8051) - mean (926ms)  : 873, 978
    master - mean (924ms)  : 871, 976

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8051) - mean (269ms)  : 264, 275
    master - mean (269ms)  : 265, 273

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

    section CallTarget+Inlining+NGEN
    This PR (8051) - mean (929ms)  : 897, 961
    master - mean (926ms)  : 882, 970

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8051) - mean (272ms)  : 261, 282
    master - mean (275ms)  : 268, 281

    section Bailout
    This PR (8051) - mean (270ms)  : 265, 275
    master - mean (268ms)  : 265, 272

    section CallTarget+Inlining+NGEN
    This PR (8051) - mean (826ms)  : 808, 843
    master - mean (823ms)  : 805, 842

Loading

@andrewlock andrewlock merged commit 31949a5 into master Jan 15, 2026
151 checks passed
@andrewlock andrewlock deleted the andrew/update-ff-api branch January 15, 2026 15:11
@github-actions github-actions bot added this to the vNext-v3 milestone Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) feature_flags type:performance Performance, speed, latency, resource usage (CPU, memory)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants