-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ASM] Fix our legacy encoder benchmarks memory leak #5308
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 330073 Passed, 1582 Skipped, 48m 9.64s Wall Time New Flaky Tests (2)
⌛ Performance Regressions vs Default Branch (1)
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing the following branches/commits: 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 shown in red. The following thresholds were used for comparing the execution times:
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). gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.6.2)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5308) - mean (74ms) : 66, 82
. : milestone, 74,
master - mean (76ms) : 64, 87
. : milestone, 76,
section CallTarget+Inlining+NGEN
This PR (5308) - mean (1,002ms) : 976, 1029
. : milestone, 1002,
master - mean (1,002ms) : 981, 1022
. : milestone, 1002,
gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5308) - mean (110ms) : 107, 112
. : milestone, 110,
master - mean (110ms) : 107, 112
. : milestone, 110,
section CallTarget+Inlining+NGEN
This PR (5308) - mean (718ms) : 696, 739
. : milestone, 718,
master - mean (718ms) : 694, 741
. : milestone, 718,
gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5308) - mean (94ms) : 90, 98
. : milestone, 94,
master - mean (95ms) : 91, 99
. : milestone, 95,
section CallTarget+Inlining+NGEN
This PR (5308) - mean (678ms) : 658, 697
. : milestone, 678,
master - mean (676ms) : 653, 698
. : milestone, 676,
gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5308) - mean (188ms) : 186, 191
. : milestone, 188,
master - mean (188ms) : 184, 192
. : milestone, 188,
section CallTarget+Inlining+NGEN
This PR (5308) - mean (1,079ms) : 1056, 1103
. : milestone, 1079,
master - mean (1,080ms) : 1058, 1102
. : milestone, 1080,
gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5308) - mean (288ms) : 278, 298
. : milestone, 288,
master - mean (272ms) : 268, 276
. : milestone, 272,
section CallTarget+Inlining+NGEN
This PR (5308) - mean (874ms) : 844, 904
. : milestone, 874,
master - mean (874ms) : 853, 895
. : milestone, 874,
gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5308) - mean (261ms) : 255, 267
. : milestone, 261,
master - mean (260ms) : 254, 265
. : milestone, 260,
section CallTarget+Inlining+NGEN
This PR (5308) - mean (852ms) : 828, 876
. : milestone, 852,
master - mean (850ms) : 827, 872
. : milestone, 850,
|
Benchmarks Report for tracer 🐌Benchmarks for #5308 compared to master:
The following thresholds were used for comparing the benchmark speeds:
Allocation changes below 0.5% are ignored. Benchmark detailsBenchmarks.Trace.ActivityBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.SpanBenchmark - Slower
|
Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality |
---|---|---|---|---|
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑netcoreapp3.1 | 1.122 | 639.01 | 716.88 |
Benchmark | base/diff | Base Median (ns) | Diff Median (ns) | Modality |
---|---|---|---|---|
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑net6.0 | 1.117 | 662.93 | 593.73 |
Raw results
Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|---|
master | StartFinishSpan |
net6.0 | 477ns | 0.588ns | 2.2ns | 0.00765 | 0 | 0 | 552 B |
master | StartFinishSpan |
netcoreapp3.1 | 639ns | 0.885ns | 3.43ns | 0.00757 | 0 | 0 | 552 B |
master | StartFinishSpan |
net472 | 781ns | 1.37ns | 5.31ns | 0.088 | 0 | 0 | 554 B |
master | StartFinishScope |
net6.0 | 662ns | 1.04ns | 4.03ns | 0.00954 | 0 | 0 | 672 B |
master | StartFinishScope |
netcoreapp3.1 | 922ns | 1.18ns | 4.42ns | 0.00926 | 0 | 0 | 672 B |
master | StartFinishScope |
net472 | 940ns | 0.797ns | 3.09ns | 0.101 | 0 | 0 | 634 B |
#5308 | StartFinishSpan |
net6.0 | 474ns | 0.691ns | 2.68ns | 0.00762 | 0 | 0 | 552 B |
#5308 | StartFinishSpan |
netcoreapp3.1 | 718ns | 0.982ns | 3.8ns | 0.0077 | 0 | 0 | 552 B |
#5308 | StartFinishSpan |
net472 | 790ns | 0.993ns | 3.85ns | 0.0876 | 0 | 0 | 554 B |
#5308 | StartFinishScope |
net6.0 | 593ns | 0.438ns | 1.69ns | 0.00937 | 0 | 0 | 672 B |
#5308 | StartFinishScope |
netcoreapp3.1 | 830ns | 0.981ns | 3.8ns | 0.00896 | 0 | 0 | 672 B |
#5308 | StartFinishScope |
net472 | 947ns | 1.23ns | 4.62ns | 0.1 | 0 | 0 | 634 B |
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed ✔️ Same allocations ✔️
Raw results
Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|---|
master | RunOnMethodBegin |
net6.0 | 678ns | 1.16ns | 4.5ns | 0.00923 | 0 | 0 | 672 B |
master | RunOnMethodBegin |
netcoreapp3.1 | 980ns | 1.17ns | 4.55ns | 0.00932 | 0 | 0 | 672 B |
master | RunOnMethodBegin |
net472 | 1.07μs | 1.15ns | 4.44ns | 0.1 | 0 | 0 | 634 B |
#5308 | RunOnMethodBegin |
net6.0 | 682ns | 0.854ns | 3.31ns | 0.0094 | 0 | 0 | 672 B |
#5308 | RunOnMethodBegin |
netcoreapp3.1 | 991ns | 1.49ns | 5.77ns | 0.00916 | 0 | 0 | 672 B |
#5308 | RunOnMethodBegin |
net472 | 1.09μs | 1.47ns | 5.29ns | 0.1 | 0 | 0 | 634 B |
6f768e7
to
2db40cb
Compare
Benchmarks Report for appsec 🐌Benchmarks for #5308 compared to master:
The following thresholds were used for comparing the benchmark speeds:
Allocation changes below 0.5% are ignored. Benchmark detailsBenchmarks.Trace.Asm.AppSecBodyBenchmark - Slower
|
Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality |
---|---|---|---|---|
Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody‑netcoreapp3.1 | 1.123 | 205.66 | 231.05 |
Raw results
Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|---|
master | AllCycleSimpleBody |
net6.0 | 71.3μs | 85.6ns | 332ns | 0.0711 | 0 | 0 | 5.97 KB |
master | AllCycleSimpleBody |
netcoreapp3.1 | 61.9μs | 97.2ns | 377ns | 0.0926 | 0 | 0 | 6.92 KB |
master | AllCycleSimpleBody |
net472 | 48.2μs | 51.5ns | 193ns | 1.3 | 0 | 0 | 8.3 KB |
master | AllCycleMoreComplexBody |
net6.0 | 76.6μs | 142ns | 550ns | 0.113 | 0 | 0 | 9.48 KB |
master | AllCycleMoreComplexBody |
netcoreapp3.1 | 67.7μs | 81.8ns | 317ns | 0.136 | 0 | 0 | 10.33 KB |
master | AllCycleMoreComplexBody |
net472 | 55.4μs | 35.4ns | 128ns | 1.86 | 0.0278 | 0 | 11.82 KB |
master | ObjectExtractorSimpleBody |
net6.0 | 145ns | 0.119ns | 0.46ns | 0.00397 | 0 | 0 | 280 B |
master | ObjectExtractorSimpleBody |
netcoreapp3.1 | 206ns | 0.156ns | 0.602ns | 0.00373 | 0 | 0 | 272 B |
master | ObjectExtractorSimpleBody |
net472 | 160ns | 0.156ns | 0.606ns | 0.0446 | 0 | 0 | 281 B |
master | ObjectExtractorMoreComplexBody |
net6.0 | 3.02μs | 2ns | 7.49ns | 0.0532 | 0 | 0 | 3.78 KB |
master | ObjectExtractorMoreComplexBody |
netcoreapp3.1 | 4.49μs | 2.22ns | 8.32ns | 0.0494 | 0 | 0 | 3.69 KB |
master | ObjectExtractorMoreComplexBody |
net472 | 3.75μs | 2.13ns | 8.26ns | 0.603 | 0.00563 | 0 | 3.8 KB |
#5308 | AllCycleSimpleBody |
net6.0 | 69.8μs | 49.9ns | 193ns | 0.0697 | 0 | 0 | 5.97 KB |
#5308 | AllCycleSimpleBody |
netcoreapp3.1 | 60.9μs | 64.5ns | 250ns | 0.0904 | 0 | 0 | 6.92 KB |
#5308 | AllCycleSimpleBody |
net472 | 47.8μs | 29.1ns | 109ns | 1.3 | 0 | 0 | 8.3 KB |
#5308 | AllCycleMoreComplexBody |
net6.0 | 76.7μs | 94.4ns | 366ns | 0.116 | 0 | 0 | 9.48 KB |
#5308 | AllCycleMoreComplexBody |
netcoreapp3.1 | 70.1μs | 101ns | 379ns | 0.137 | 0 | 0 | 10.33 KB |
#5308 | AllCycleMoreComplexBody |
net472 | 55.5μs | 60.4ns | 234ns | 1.86 | 0.0277 | 0 | 11.82 KB |
#5308 | ObjectExtractorSimpleBody |
net6.0 | 141ns | 0.0904ns | 0.338ns | 0.00395 | 0 | 0 | 280 B |
#5308 | ObjectExtractorSimpleBody |
netcoreapp3.1 | 231ns | 0.167ns | 0.624ns | 0.00372 | 0 | 0 | 272 B |
#5308 | ObjectExtractorSimpleBody |
net472 | 164ns | 0.153ns | 0.593ns | 0.0446 | 0 | 0 | 281 B |
#5308 | ObjectExtractorMoreComplexBody |
net6.0 | 3.02μs | 2.62ns | 10.2ns | 0.0533 | 0 | 0 | 3.78 KB |
#5308 | ObjectExtractorMoreComplexBody |
netcoreapp3.1 | 4.06μs | 2.01ns | 7.79ns | 0.0486 | 0 | 0 | 3.69 KB |
#5308 | ObjectExtractorMoreComplexBody |
net472 | 3.82μs | 4.84ns | 18.8ns | 0.601 | 0.00575 | 0 | 3.8 KB |
Benchmarks.Trace.Asm.AppSecEncoderBenchmark - Same speed ✔️ Same allocations ✔️
Raw results
Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|---|
#5308 | EncodeArgs |
net6.0 | 39.9μs | 43.2ns | 167ns | 0.456 | 0 | 0 | 32.4 KB |
#5308 | EncodeArgs |
netcoreapp3.1 | 56.1μs | 25ns | 93.7ns | 0.445 | 0 | 0 | 32.4 KB |
#5308 | EncodeArgs |
net472 | 69.5μs | 34.6ns | 134ns | 5.14 | 0.0695 | 0 | 32.5 KB |
#5308 | EncodeLegacyArgs |
net6.0 | 71.7μs | 33.8ns | 131ns | 0 | 0 | 0 | 2.14 KB |
#5308 | EncodeLegacyArgs |
netcoreapp3.1 | 104μs | 174ns | 651ns | 0 | 0 | 0 | 2.14 KB |
#5308 | EncodeLegacyArgs |
net472 | 158μs | 85.3ns | 330ns | 0.315 | 0 | 0 | 2.15 KB |
Benchmarks.Trace.Asm.AppSecWafBenchmark - Same speed ✔️ Fewer allocations 🎉
Fewer allocations 🎉 in #5308
Benchmark
Base Allocated
Diff Allocated
Change
Change %
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack‑net472
4.19 KB
1.39 KB
-2.8 KB
-66.87%
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack‑net6.0
4.15 KB
1.37 KB
-2.78 KB
-67.05%
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark‑net472
6.59 KB
2.17 KB
-4.42 KB
-67.12%
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack‑netcoreapp3.1
4.14 KB
1.36 KB
-2.78 KB
-67.18%
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark‑net6.0
6.51 KB
2.13 KB
-4.39 KB
-67.33%
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark‑netcoreapp3.1
6.49 KB
2.1 KB
-4.38 KB
-67.57%
Benchmark | Base Allocated | Diff Allocated | Change | Change % |
---|---|---|---|---|
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack‑net472 | 4.19 KB | 1.39 KB | -2.8 KB | -66.87% |
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack‑net6.0 | 4.15 KB | 1.37 KB | -2.78 KB | -67.05% |
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark‑net472 | 6.59 KB | 2.17 KB | -4.42 KB | -67.12% |
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack‑netcoreapp3.1 | 4.14 KB | 1.36 KB | -2.78 KB | -67.18% |
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark‑net6.0 | 6.51 KB | 2.13 KB | -4.39 KB | -67.33% |
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark‑netcoreapp3.1 | 6.49 KB | 2.1 KB | -4.38 KB | -67.57% |
Raw results
Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|---|
master | RunWafRealisticBenchmark |
net6.0 | 191μs | 782ns | 3.03μs | 0 | 0 | 0 | 6.51 KB |
master | RunWafRealisticBenchmark |
netcoreapp3.1 | 203μs | 194ns | 750ns | 0 | 0 | 0 | 6.49 KB |
master | RunWafRealisticBenchmark |
net472 | 223μs | 107ns | 415ns | 0.997 | 0 | 0 | 6.59 KB |
master | RunWafRealisticBenchmarkWithAttack |
net6.0 | 125μs | 149ns | 576ns | 0 | 0 | 0 | 4.15 KB |
master | RunWafRealisticBenchmarkWithAttack |
netcoreapp3.1 | 134μs | 187ns | 725ns | 0 | 0 | 0 | 4.14 KB |
master | RunWafRealisticBenchmarkWithAttack |
net472 | 148μs | 296ns | 1.15μs | 0.657 | 0 | 0 | 4.19 KB |
#5308 | RunWafRealisticBenchmark |
net6.0 | 182μs | 290ns | 1.12μs | 0 | 0 | 0 | 2.13 KB |
#5308 | RunWafRealisticBenchmark |
netcoreapp3.1 | 195μs | 166ns | 622ns | 0 | 0 | 0 | 2.1 KB |
#5308 | RunWafRealisticBenchmark |
net472 | 217μs | 136ns | 525ns | 0.322 | 0 | 0 | 2.17 KB |
#5308 | RunWafRealisticBenchmarkWithAttack |
net6.0 | 122μs | 36ns | 135ns | 0 | 0 | 0 | 1.37 KB |
#5308 | RunWafRealisticBenchmarkWithAttack |
netcoreapp3.1 | 130μs | 137ns | 531ns | 0 | 0 | 0 | 1.36 KB |
#5308 | RunWafRealisticBenchmarkWithAttack |
net472 | 142μs | 65ns | 243ns | 0.212 | 0 | 0 | 1.39 KB |
Benchmarks.Trace.Iast.StringAspectsBenchmark - Same speed ✔️ More allocations ⚠️
More allocations ⚠️ in #5308
Benchmark
Base Allocated
Diff Allocated
Change
Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net6.0
201.19 KB
209.92 KB
8.73 KB
4.34%
Fewer allocations 🎉 in #5308
Benchmark
Base Allocated
Diff Allocated
Change
Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark‑net472
61.7 KB
57.9 KB
-3.81 KB
-6.17%
Benchmark | Base Allocated | Diff Allocated | Change | Change % |
---|---|---|---|---|
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net6.0 | 201.19 KB | 209.92 KB | 8.73 KB | 4.34% |
Benchmark | Base Allocated | Diff Allocated | Change | Change % |
---|---|---|---|---|
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark‑net472 | 61.7 KB | 57.9 KB | -3.81 KB | -6.17% |
Raw results
Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|---|
master | StringConcatBenchmark |
net6.0 | 53.8μs | 192ns | 1.29μs | 0 | 0 | 0 | 43.44 KB |
master | StringConcatBenchmark |
netcoreapp3.1 | 62.7μs | 777ns | 7.73μs | 0 | 0 | 0 | 42.64 KB |
master | StringConcatBenchmark |
net472 | 37.1μs | 174ns | 675ns | 0 | 0 | 0 | 61.7 KB |
master | StringConcatAspectBenchmark |
net6.0 | 284μs | 1.62μs | 11.2μs | 0 | 0 | 0 | 201.19 KB |
master | StringConcatAspectBenchmark |
netcoreapp3.1 | 316μs | 1.74μs | 10.2μs | 0 | 0 | 0 | 203.18 KB |
master | StringConcatAspectBenchmark |
net472 | 256μs | 4.58μs | 43.7μs | 0 | 0 | 0 | 221.18 KB |
#5308 | StringConcatBenchmark |
net6.0 | 52.5μs | 183ns | 686ns | 0 | 0 | 0 | 43.44 KB |
#5308 | StringConcatBenchmark |
netcoreapp3.1 | 64.8μs | 790ns | 7.7μs | 0 | 0 | 0 | 42.64 KB |
#5308 | StringConcatBenchmark |
net472 | 39.2μs | 198ns | 906ns | 0 | 0 | 0 | 57.9 KB |
#5308 | StringConcatAspectBenchmark |
net6.0 | 289μs | 5.93μs | 57.5μs | 0 | 0 | 0 | 209.92 KB |
#5308 | StringConcatAspectBenchmark |
netcoreapp3.1 | 311μs | 1.73μs | 11.1μs | 0 | 0 | 0 | 202.29 KB |
#5308 | StringConcatAspectBenchmark |
net472 | 254μs | 3.28μs | 31μs | 0 | 0 | 0 | 221.18 KB |
648b393
to
6307468
Compare
82f0455
to
babe539
Compare
private readonly IntPtr _freeObjectFuncField; | ||
private readonly SetupLoggingDelegate _setupLogging; | ||
private readonly SetupLogCallbackDelegate _setupLogCallbackField; | ||
private readonly UpdateDelegate _updateField; | ||
private string _version = null; | ||
internal static int SizeOfDdWafObject = Marshal.SizeOf(typeof(DdwafObjectStruct)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not needed anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes removed in 7ae7027
@@ -112,9 +112,9 @@ private static void LogRuleDetailsIfDebugEnabled(JToken root) | |||
return root; | |||
} | |||
|
|||
internal InitResult Configure(IntPtr rulesObj, IEncoder encoder, DdwafConfigStruct configStruct, ref DdwafObjectStruct diagnostics, string? rulesFile) | |||
internal InitResult Configure(DdwafObjectStruct rulesObj, IEncoder encoder, DdwafConfigStruct configStruct, ref DdwafObjectStruct diagnostics, string? rulesFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: You could change it to ref DdwafObjectStruct rulesObj
to avoid the copy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes changed in 7ae7027
|
||
internal void ObjectFreePtr(ref IntPtr input) | ||
internal void ObjectFreePtr(IntPtr input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could make it ObjectFreePtr(ref DdwafObjectStruct input);
to simplify it the same way as you did for Result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes changed in 7ae7027
It makes me do tricks in Obj
as I have to:
if (_handle is not null && _handle.Value.Target is not null)
{
var item = (DdwafObjectStruct)_handle.Value.Target;
wafLibraryInvoker.ObjectFree(ref item);
_handle.Value.Free();
}
but it works :)
nb: the ddwafobject struct tree is not always disposed on the stack, it's disposed later at the end of the request's lifecycle
{ | ||
UpdateResult? res = null; | ||
DdwafObjectStruct? diagnostics = null; | ||
var diagnosticsValue = new DdwafObjectStruct { Type = DDWAF_OBJ_TYPE.DDWAF_OBJ_MAP }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you call ObjectMap()
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the objects is filled by the update function called on the waf as well as the creation function one and it's all good when we dispose it calling the ObjectFree function from the waf on it so I guess it's all good and avoids a p'invoke like this ..
DDWAF_OBJ_TYPE.DDWAF_OBJ_INVALID => ObjType.Invalid, | ||
DDWAF_OBJ_TYPE.DDWAF_OBJ_SIGNED => ObjType.SignedNumber, | ||
DDWAF_OBJ_TYPE.DDWAF_OBJ_UNSIGNED => ObjType.UnsignedNumber, | ||
DDWAF_OBJ_TYPE.DDWAF_OBJ_STRING => ObjType.String, | ||
DDWAF_OBJ_TYPE.DDWAF_OBJ_BOOL => ObjType.Bool, | ||
DDWAF_OBJ_TYPE.DDWAF_OBJ_DOUBLE => ObjType.Double, | ||
DDWAF_OBJ_TYPE.DDWAF_OBJ_ARRAY => ObjType.Array, | ||
DDWAF_OBJ_TYPE.DDWAF_OBJ_MAP => ObjType.Map, | ||
DDWAF_OBJ_TYPE.DDWAF_OBJ_NULL => ObjType.Null, | ||
_ => throw new Exception($"Invalid DDWAF_INPUT_TYPE {t}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a 1:1 mapping between the values, you could just do return (ObjType)t;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed in 7ae7027
using Datadog.Trace.AppSec.Waf.NativeBindings; | ||
|
||
namespace Datadog.Trace.AppSec.WafEncoding | ||
{ | ||
// NOTE: this is referred to as ddwaf_object in the C++ code, we call it Obj to avoid a naming clash | ||
internal class Obj : IDisposable | ||
internal class Obj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this class still needed? As long as DdwafObjectStruct is on the stack, it doesn't need to be pinned. I feel like you should be able to directly return DdwafObjectStruct where you currently use Obj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but we still need to pin the parent DdWafObjectStruct
to dispose its reference later :/ as it's not always disposed within the method RunWaf
, the list of Obj
build up within the Context
and need to be disposed only at the end of the request when the context is destroyed... so we need to pin them somewhere.. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, many thanks!
f27ee3d
to
bb6eb68
Compare
Summary of changes
Remove all allocations of memory and create
DdWafObjectStruct
on the stack.Don't configure a free function to execute on context destroy and call the waf free function ourselves, only on parent
Reason for change
Implementation details
Test coverage
Other details