Skip to content

Conversation

@andrewlock
Copy link
Member

Summary of changes

  • Add #nullable enable to a bunch of files
  • Fix NullReferenceException in DynamoDB integrations

Reason for change

While looking at logs, spotted null reference exception in DynamoDB integration. Adding #nullable enable (and being conservative about what could be null) revealed multiple cases

Implementation details

  • Add #nullable enable to DynamoDB duck types and integrations
  • Update source generator to respect updated nullability
  • Fixed incorrect access on null objects
  • Add missing dispose on enumerator

Test coverage

Should be covered by existing. These are generally edge cases

Other details

Made other cosmetic changes too, removing unnecessary comments and namespaces etc. Recommend commit-by-commit review for simplicity (bug-fixes are isolated to a single commit)

@andrewlock andrewlock requested a review from a team as a code owner November 20, 2025 12:36
@andrewlock andrewlock requested review from a team as code owners November 20, 2025 12:36
@andrewlock andrewlock requested a review from a team as a code owner November 20, 2025 12:36
@dd-trace-dotnet-ci-bot
Copy link

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (7849) 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
duration75.38 ± (75.49 - 76.20) ms74.48 ± (74.45 - 75.06) ms-1.2%
.NET Framework 4.8 - Bailout
duration79.76 ± (79.52 - 80.18) ms79.95 ± (79.88 - 80.57) ms+0.2%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1109.88 ± (1111.58 - 1122.37) ms1110.94 ± (1109.29 - 1116.96) ms+0.1%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms23.00 ± (22.93 - 23.07) ms23.07 ± (22.97 - 23.16) ms+0.3%✅⬆️
process.time_to_main_ms87.18 ± (86.84 - 87.52) ms87.45 ± (87.10 - 87.80) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.91 ± (10.91 - 10.91) MB10.91 ± (10.90 - 10.91) MB-0.0%
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms22.75 ± (22.69 - 22.81) ms22.81 ± (22.75 - 22.87) ms+0.3%✅⬆️
process.time_to_main_ms87.56 ± (87.19 - 87.93) ms88.10 ± (87.78 - 88.43) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.95 ± (10.94 - 10.95) MB10.95 ± (10.95 - 10.96) MB+0.1%✅⬆️
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms218.72 ± (217.39 - 220.04) ms219.47 ± (218.03 - 220.92) ms+0.3%✅⬆️
process.time_to_main_ms548.05 ± (546.77 - 549.33) ms543.44 ± (542.27 - 544.61) ms-0.8%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed52.62 ± (52.60 - 52.64) MB52.52 ± (52.50 - 52.54) MB-0.2%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.2%
.NET 6 - Baseline
process.internal_duration_ms21.67 ± (21.60 - 21.74) ms21.79 ± (21.71 - 21.87) ms+0.6%✅⬆️
process.time_to_main_ms75.78 ± (75.42 - 76.13) ms76.46 ± (76.11 - 76.81) ms+0.9%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.61 ± (10.61 - 10.62) MB10.64 ± (10.64 - 10.64) MB+0.2%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms21.86 ± (21.79 - 21.94) ms21.65 ± (21.58 - 21.71) ms-1.0%
process.time_to_main_ms78.17 ± (77.79 - 78.54) ms76.93 ± (76.64 - 77.23) ms-1.6%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.67 ± (10.67 - 10.67) MB10.68 ± (10.67 - 10.68) MB+0.0%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms206.31 ± (204.95 - 207.67) ms206.37 ± (205.06 - 207.67) ms+0.0%✅⬆️
process.time_to_main_ms513.43 ± (512.06 - 514.80) ms509.40 ± (508.46 - 510.33) ms-0.8%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed51.86 ± (51.83 - 51.89) MB51.50 ± (51.48 - 51.53) MB-0.7%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms19.88 ± (19.81 - 19.95) ms19.74 ± (19.67 - 19.80) ms-0.7%
process.time_to_main_ms75.61 ± (75.27 - 75.94) ms74.24 ± (73.90 - 74.57) ms-1.8%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.66 ± (7.66 - 7.67) MB7.64 ± (7.64 - 7.65) MB-0.3%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.64 ± (19.58 - 19.70) ms19.78 ± (19.72 - 19.85) ms+0.7%✅⬆️
process.time_to_main_ms75.86 ± (75.57 - 76.14) ms77.12 ± (76.78 - 77.46) ms+1.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.71 ± (7.70 - 7.72) MB7.69 ± (7.69 - 7.70) MB-0.2%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms191.79 ± (190.93 - 192.66) ms189.61 ± (188.71 - 190.51) ms-1.1%
process.time_to_main_ms492.11 ± (491.10 - 493.13) ms485.19 ± (484.25 - 486.13) ms-1.4%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed38.97 ± (38.93 - 39.01) MB38.68 ± (38.65 - 38.71) MB-0.7%
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.05 ± (191.97 - 192.89) ms191.84 ± (192.06 - 192.90) ms-0.1%
.NET Framework 4.8 - Bailout
duration195.26 ± (195.04 - 195.57) ms195.38 ± (195.24 - 195.83) ms+0.1%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1163.36 ± (1164.37 - 1172.84) ms1166.54 ± (1170.41 - 1179.88) ms+0.3%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms189.26 ± (188.81 - 189.70) ms188.23 ± (187.80 - 188.66) ms-0.5%
process.time_to_main_ms81.34 ± (81.06 - 81.62) ms80.69 ± (80.44 - 80.93) ms-0.8%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.05 ± (16.02 - 16.08) MB16.11 ± (16.08 - 16.13) MB+0.4%✅⬆️
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (19 - 20)+0.3%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms187.33 ± (187.01 - 187.65) ms187.04 ± (186.69 - 187.40) ms-0.2%
process.time_to_main_ms81.96 ± (81.84 - 82.07) ms81.73 ± (81.59 - 81.87) ms-0.3%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.12 ± (16.09 - 16.15) MB16.18 ± (16.14 - 16.23) MB+0.4%✅⬆️
runtime.dotnet.threads.count21 ± (20 - 21)21 ± (20 - 21)+0.2%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms394.95 ± (392.64 - 397.26) ms397.98 ± (395.38 - 400.57) ms+0.8%✅⬆️
process.time_to_main_ms518.95 ± (518.27 - 519.62) ms514.42 ± (513.73 - 515.11) ms-0.9%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed63.05 ± (62.89 - 63.21) MB63.11 ± (62.98 - 63.25) MB+0.1%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 30)+0.1%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms192.46 ± (192.07 - 192.84) ms192.07 ± (191.76 - 192.37) ms-0.2%
process.time_to_main_ms70.02 ± (69.83 - 70.22) ms69.91 ± (69.74 - 70.07) ms-0.2%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.34 ± (16.31 - 16.37) MB16.19 ± (16.06 - 16.32) MB-0.9%
runtime.dotnet.threads.count19 ± (19 - 19)18 ± (18 - 19)-3.9%
.NET 6 - Bailout
process.internal_duration_ms191.03 ± (190.75 - 191.31) ms190.95 ± (190.60 - 191.29) ms-0.0%
process.time_to_main_ms70.89 ± (70.77 - 71.00) ms70.86 ± (70.74 - 70.97) ms-0.0%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.14 ± (16.00 - 16.29) MB16.19 ± (16.04 - 16.33) MB+0.3%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 20)+0.4%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms411.77 ± (408.71 - 414.83) ms408.78 ± (405.91 - 411.66) ms-0.7%
process.time_to_main_ms487.60 ± (487.05 - 488.14) ms484.71 ± (484.14 - 485.28) ms-0.6%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed62.16 ± (62.02 - 62.30) MB61.73 ± (61.58 - 61.88) MB-0.7%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.0%
.NET 8 - Baseline
process.internal_duration_ms190.46 ± (190.15 - 190.76) ms190.10 ± (189.83 - 190.37) ms-0.2%
process.time_to_main_ms69.42 ± (69.28 - 69.56) ms69.60 ± (69.45 - 69.76) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.72 ± (11.69 - 11.75) MB11.83 ± (11.80 - 11.85) MB+0.9%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)+0.6%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms189.46 ± (189.21 - 189.70) ms189.57 ± (189.21 - 189.93) ms+0.1%✅⬆️
process.time_to_main_ms70.39 ± (70.29 - 70.49) ms70.35 ± (70.26 - 70.44) ms-0.1%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.79 ± (11.76 - 11.83) MB11.89 ± (11.85 - 11.93) MB+0.8%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.1%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms361.79 ± (360.17 - 363.40) ms360.72 ± (359.16 - 362.27) ms-0.3%
process.time_to_main_ms463.84 ± (463.38 - 464.29) ms459.12 ± (458.46 - 459.78) ms-1.0%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed50.44 ± (50.40 - 50.49) MB50.13 ± (50.09 - 50.17) MB-0.6%
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 (7849) - mean (75ms)  : 70, 79
    master - mean (76ms)  : 71, 81

    section Bailout
    This PR (7849) - mean (80ms)  : 75, 85
    master - mean (80ms)  : 75, 85

    section CallTarget+Inlining+NGEN
    This PR (7849) - mean (1,113ms)  : 1057, 1169
    master - mean (1,117ms)  : 1038, 1196

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 (7849) - mean (118ms)  : 112, 124
    master - mean (118ms)  : 110, 125

    section Bailout
    This PR (7849) - mean (118ms)  : 113, 123
    master - mean (118ms)  : 111, 125

    section CallTarget+Inlining+NGEN
    This PR (7849) - mean (796ms)  : 752, 839
    master - mean (800ms)  : 758, 841

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7849) - mean (105ms)  : 99, 112
    master - mean (104ms)  : 97, 111

    section Bailout
    This PR (7849) - mean (105ms)  : 100, 111
    master - mean (107ms)  : 100, 114

    section CallTarget+Inlining+NGEN
    This PR (7849) - mean (745ms)  : 713, 777
    master - mean (754ms)  : 711, 797

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7849) - mean (102ms)  : 96, 109
    master - mean (104ms)  : 98, 110

    section Bailout
    This PR (7849) - mean (105ms)  : 98, 113
    master - mean (104ms)  : 99, 109

    section CallTarget+Inlining+NGEN
    This PR (7849) - mean (706ms)  : 680, 732
    master - mean (715ms)  : 689, 740

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 (7849) - mean (192ms)  : 188, 197
    master - mean (192ms)  : 188, 197

    section Bailout
    This PR (7849) - mean (196ms)  : 193, 198
    master - mean (195ms)  : 193, 198

    section CallTarget+Inlining+NGEN
    This PR (7849) - mean (1,175ms)  : 1104, 1246
    master - mean (1,169ms)  : 1105, 1232

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 (7849) - mean (277ms)  : 269, 285
    master - mean (279ms)  : 274, 284

    section Bailout
    This PR (7849) - mean (277ms)  : 272, 283
    master - mean (277ms)  : 273, 281

    section CallTarget+Inlining+NGEN
    This PR (7849) - mean (947ms)  : 903, 991
    master - mean (947ms)  : 911, 984

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7849) - mean (270ms)  : 266, 274
    master - mean (271ms)  : 266, 275

    section Bailout
    This PR (7849) - mean (270ms)  : 265, 274
    master - mean (270ms)  : 265, 274

    section CallTarget+Inlining+NGEN
    This PR (7849) - mean (928ms)  : 876, 979
    master - mean (931ms)  : 882, 979

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7849) - mean (269ms)  : 266, 273
    master - mean (270ms)  : 265, 274

    section Bailout
    This PR (7849) - mean (269ms)  : 265, 274
    master - mean (269ms)  : 265, 274

    section CallTarget+Inlining+NGEN
    This PR (7849) - mean (852ms)  : 829, 874
    master - mean (857ms)  : 836, 879

Loading

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.

Nice! Thanks!

var tableName = request.TableName;
try
{
var keys = request.Keys.DuckCast<IDynamoDbKeysObject>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thought this was a possible null reference exception scenario, but then, realized that:
public static T? DuckCast()


// TableName tagging only when batch is from one table.
var iterator = request.RequestItems.GetEnumerator();
using var disposable = iterator as IDisposable;
Copy link
Member

Choose a reason for hiding this comment

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

cool trick

Comment on lines +16 to +17
/// https://github.com/aws/aws-sdk-net/blob/main/sdk/src/Services/DynamoDBv2/Generated/Model/UpdateItemRequest.cs
/// https://github.com/aws/aws-sdk-net/blob/main/sdk/src/Services/DynamoDBv2/Generated/Model/DeleteItemRequest.cs
Copy link
Member

Choose a reason for hiding this comment

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

thanks!

Copy link
Member

@lucaspimentel lucaspimentel left a comment

Choose a reason for hiding this comment

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

Thanks!

@andrewlock andrewlock merged commit 55cc088 into master Nov 21, 2025
154 checks passed
@andrewlock andrewlock deleted the andrew/null-ref-in-dynamodb branch November 21, 2025 12:23
@github-actions github-actions bot added this to the vNext-v3 milestone Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants