Update FeatureFlagsEvaluator and Debugger ToUUID to not violate CA1850#8303
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3dbf668fa0
ℹ️ 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".
| ? stackalloc byte[512] | ||
| : new byte[maxInputSize]; | ||
|
|
||
| var encodeCount = EncodingHelpers.Utf8NoBom.GetBytes(input, inputBuffer); |
There was a problem hiding this comment.
Keep MD5 input encoding tolerant of invalid surrogates
Using EncodingHelpers.Utf8NoBom.GetBytes(...) here changes behavior from the previous Encoding.UTF8.GetBytes(...): Utf8NoBom is configured with throwOnInvalidBytes: true, so inputs containing unpaired UTF-16 surrogates now throw EncoderFallbackException instead of being replacement-encoded and hashed. In this commit that affects both feature-flag sharding and debugger UUID generation, meaning certain user-provided keys that previously hashed deterministically now trigger error/default paths.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Interesting 🤔 That's probably still what we want, but I didn't realise it was different...
There was a problem hiding this comment.
Do the callers handle the error-path change correctly?
There was a problem hiding this comment.
Do the callers handle the error-path change correctly?
In short "no", but there's no actual change to the error-path. The throwOnInvalidBytes:true case will only throw when you're trying to get a string from a byte[]. In this case we're going the other way - we have a valid string, so we can always convert it to a byte[], there can't be any issues with unpaired surrogates I believe
BenchmarksBenchmark execution time: 2026-03-17 16:06:55 Comparing candidate commit 419d7ed in PR branch Found 6 performance improvements and 5 performance regressions! Performance is the same for 166 metrics, 15 unstable metrics. scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net6.0
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1
scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net6.0
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8303) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-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:
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 chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8303) - mean (76ms) : 73, 79
master - mean (75ms) : 72, 78
section Bailout
This PR (8303) - mean (81ms) : 78, 84
master - mean (79ms) : 77, 81
section CallTarget+Inlining+NGEN
This PR (8303) - mean (1,111ms) : 1064, 1158
master - mean (1,099ms) : 1063, 1135
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 (8303) - mean (120ms) : 116, 123
master - mean (119ms) : 115, 122
section Bailout
This PR (8303) - mean (122ms) : 119, 125
master - mean (120ms) : 117, 123
section CallTarget+Inlining+NGEN
This PR (8303) - mean (767ms) : 744, 791
master - mean (769ms) : 746, 791
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8303) - mean (106ms) : 103, 108
master - mean (105ms) : 102, 107
section Bailout
This PR (8303) - mean (106ms) : 103, 110
master - mean (105ms) : 103, 108
section CallTarget+Inlining+NGEN
This PR (8303) - mean (756ms) : 719, 792
master - mean (750ms) : 703, 796
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8303) - mean (106ms) : 102, 111
master - mean (104ms) : 101, 108
section Bailout
This PR (8303) - mean (105ms) : 103, 107
master - mean (105ms) : 103, 108
section CallTarget+Inlining+NGEN
This PR (8303) - mean (699ms) : 674, 725
master - mean (694ms) : 670, 718
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 (8303) - mean (198ms) : 190, 205
master - mean (194ms) : 189, 199
section Bailout
This PR (8303) - mean (201ms) : 197, 205
master - mean (198ms) : 195, 202
section CallTarget+Inlining+NGEN
This PR (8303) - mean (1,180ms) : 1105, 1254
master - mean (1,156ms) : 1097, 1214
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 (8303) - mean (282ms) : 273, 291
master - mean (278ms) : 272, 285
section Bailout
This PR (8303) - mean (282ms) : 277, 287
master - mean (278ms) : 273, 283
section CallTarget+Inlining+NGEN
This PR (8303) - mean (910ms) : 875, 945
master - mean (901ms) : 872, 931
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8303) - mean (274ms) : 268, 280
master - mean (271ms) : 265, 278
section Bailout
This PR (8303) - mean (274ms) : 269, 280
master - mean (271ms) : 266, 276
section CallTarget+Inlining+NGEN
This PR (8303) - mean (942ms) : 906, 979
master - mean (942ms) : 918, 965
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8303) - mean (271ms) : 264, 278
master - mean (269ms) : 264, 274
section Bailout
This PR (8303) - mean (271ms) : 267, 275
master - mean (270ms) : 264, 275
section CallTarget+Inlining+NGEN
This PR (8303) - mean (844ms) : 821, 868
master - mean (839ms) : 816, 862
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3dbf668 to
1e96d16
Compare
c344219 to
5c769bb
Compare
1e96d16 to
d7a3f14
Compare
dudikeleti
left a comment
There was a problem hiding this comment.
LGTM👍. Left one question.
d7a3f14 to
419d7ed
Compare
| var intFromHash = Convert.ToInt64(first8Chars, 16); | ||
| #if NETCOREAPP | ||
| // MD5 always produces a 16 byte hash | ||
| Span<byte> hashBytes = stackalloc byte[16]; |
Summary of changes
Enables the CA1850 analyzer, and fixes the two existing violations
Reason for change
The CA1850 analyzer says "use the static
MD5.HashDatainstead ofMD5.Create()etc. We need to use#ifbecause it's only in .NET Core.However, in looking at the violations, I saw there was a big opportunity for allocation and speed improvements too, so did them together
Implementation details
Md5Helper.ComputeMd5Hash()method that takes astring, converts to UTF-8, and computes the hash, as efficiently as possibly (stackalloc where possible etc)Test coverage
Other details
https://datadoghq.atlassian.net/browse/LANGPLAT-813
Stacked on other analyzer enablement tests: