Skip to content

[Dynamic Instrumentation] Skip arg/local when byref-like check fails#8566

Merged
dudikeleti merged 1 commit into
masterfrom
dudik/fix-byref-like-skip-instrumentation
May 7, 2026
Merged

[Dynamic Instrumentation] Skip arg/local when byref-like check fails#8566
dudikeleti merged 1 commit into
masterfrom
dudik/fix-byref-like-skip-instrumentation

Conversation

@dudikeleti

Copy link
Copy Markdown
Contributor

Summary of changes

  • In DebuggerMethodRewriter::WriteCallsToLogArgOrLocal, when IsTypeByRefLike returns a failure HRESULT, skip instrumentation for that argument/local instead of falling through.

Reason for change

  • If IsTypeByRefLike fails (e.g. metadata cannot be resolved), the rewriter previously continued and emitted LogArg/LogLocal calls for the value. If the value happened to be byref-like, this can produce invalid IL or runtime failures (InvalidProgramException, crashes when reading the byref).
  • Treating the failure conservatively avoids those failures; we already skip when the type is confirmed byref-like.

Implementation details

  • Add a continue; in the FAILED(hr) branch with a comment explaining the conservative behavior. No other changes.

Test coverage

  • No new tests in this PR; covered by existing debugger integration tests that exercise IL rewriting.
  • Did not run tests locally.

Other details

When IsTypeByRefLike fails (e.g. metadata cannot be resolved), the rewriter
previously fell through and emitted LogArg/LogLocal calls for the value. If
the value happened to be byref-like, this can produce invalid IL or runtime
failures.

Instead, treat the failure conservatively: log the warning and skip
instrumentation for that argument/local, the same way we already do when the
type is confirmed byref-like.

Co-authored-by: Cursor <[email protected]>
@dudikeleti
dudikeleti requested a review from a team as a code owner May 6, 2026 10:01
@pr-commenter

pr-commenter Bot commented May 6, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-05-06 11:11:58

Comparing candidate commit bc9eea7 in PR branch dudik/fix-byref-like-skip-instrumentation with baseline commit a60cc68 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 27 metrics, 0 unstable metrics, 61 known flaky benchmarks, 26 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

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

  • 🟩 throughput [+8763.647op/s; +11197.843op/s] or [+7.366%; +9.412%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 execution_time [+304.037ms; +308.611ms] or [+150.874%; +153.144%]
  • 🟥 throughput [-47.446op/s; -43.374op/s] or [-8.536%; -7.804%]

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

  • 🟥 execution_time [+383.118ms; +384.763ms] or [+302.686%; +303.987%]
  • 🟩 throughput [+86.422op/s; +89.187op/s] or [+11.394%; +11.759%]

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

  • 🟥 execution_time [+392.009ms; +394.021ms] or [+346.913%; +348.694%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net472

  • 🟥 allocated_mem [+1.308KB; +1.308KB] or [+27.529%; +27.541%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net6.0

  • 🟥 allocated_mem [+471 bytes; +472 bytes] or [+9.977%; +9.987%]
  • 🟩 execution_time [-15.949ms; -11.776ms] or [-7.449%; -5.500%]

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

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+27.502%; +27.510%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net472

  • 🟥 allocated_mem [+1.307KB; +1.307KB] or [+105.746%; +105.759%]
  • 🟥 throughput [-268967.368op/s; -264762.106op/s] or [-27.463%; -27.034%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0

  • 🟥 allocated_mem [+471 bytes; +472 bytes] or [+38.558%; +38.566%]
  • 🟩 execution_time [-25.475ms; -20.603ms] or [-11.361%; -9.188%]
  • 🟥 throughput [-70543.481op/s; -47878.221op/s] or [-7.536%; -5.115%]

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

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+105.292%; +105.304%]
  • 🟥 throughput [-141991.042op/s; -125899.524op/s] or [-20.401%; -18.089%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net6.0

  • 🟩 throughput [+10177.097op/s; +13083.906op/s] or [+6.476%; +8.325%]

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

  • 🟩 throughput [+7263.637op/s; +9894.293op/s] or [+5.786%; +7.882%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net6.0

  • 🟩 throughput [+374506.211op/s; +391032.696op/s] or [+12.488%; +13.039%]

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

  • 🟩 execution_time [-18.523ms; -14.071ms] or [-8.538%; -6.486%]
  • 🟩 throughput [+190509.694op/s; +247185.639op/s] or [+7.562%; +9.811%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net472

  • 🟥 execution_time [+299.279ms; +300.090ms] or [+149.539%; +149.945%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net6.0

  • 🟥 execution_time [+300.431ms; +303.915ms] or [+151.508%; +153.265%]

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

  • 🟥 execution_time [+299.883ms; +302.280ms] or [+151.058%; +152.265%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net472

  • 🟥 execution_time [+296.608ms; +297.594ms] or [+145.682%; +146.167%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0

  • 🟥 execution_time [+295.219ms; +297.596ms] or [+144.321%; +145.484%]

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

  • 🟥 execution_time [+302.601ms; +304.784ms] or [+151.240%; +152.330%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net6.0

  • 🟥 execution_time [+21.527µs; +45.094µs] or [+6.873%; +14.396%]
  • 🟥 throughput [-421.077op/s; -222.737op/s] or [-13.126%; -6.943%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net472

  • 🟥 execution_time [+300.268ms; +300.952ms] or [+149.865%; +150.206%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net6.0

  • unstable execution_time [+334.098ms; +381.973ms] or [+363.011%; +415.029%]
  • 🟩 throughput [+924.245op/s; +1062.865op/s] or [+7.595%; +8.734%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest netcoreapp3.1

  • unstable execution_time [+306.650ms; +344.851ms] or [+232.836%; +261.842%]
  • 🟩 throughput [+633.415op/s; +831.954op/s] or [+6.132%; +8.054%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 allocated_mem [+2.861KB; +2.866KB] or [+5.083%; +5.091%]
  • unstable execution_time [+336.358ms; +382.993ms] or [+154.654%; +176.097%]
  • 🟥 throughput [-543.393op/s; -505.971op/s] or [-49.237%; -45.846%]

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

  • unstable execution_time [+211.058ms; +344.273ms] or [+89.944%; +146.715%]
  • 🟥 throughput [-672.749op/s; -589.225op/s] or [-44.873%; -39.301%]

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

  • 🟥 execution_time [+345.840ms; +354.501ms] or [+206.853%; +212.033%]
  • 🟥 throughput [-457.214op/s; -423.052op/s] or [-31.835%; -29.456%]

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

  • unstable throughput [+15.982op/s; +85.231op/s] or [+2.983%; +15.909%]

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

  • 🟩 execution_time [-130.816µs; -102.021µs] or [-6.627%; -5.168%]
  • 🟩 throughput [+28.595op/s; +36.446op/s] or [+5.645%; +7.195%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472

  • 🟥 execution_time [+303.443ms; +304.955ms] or [+152.808%; +153.569%]

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

  • 🟥 execution_time [+299.794ms; +301.657ms] or [+150.228%; +151.161%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch netcoreapp3.1

  • 🟥 execution_time [+302.179ms; +305.399ms] or [+151.802%; +153.419%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472

  • 🟥 execution_time [+301.704ms; +303.621ms] or [+151.506%; +152.468%]

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

  • 🟥 execution_time [+297.813ms; +299.365ms] or [+147.255%; +148.023%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync netcoreapp3.1

  • 🟥 execution_time [+303.039ms; +306.555ms] or [+153.593%; +155.376%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472

  • 🟥 execution_time [+301.712ms; +303.350ms] or [+151.432%; +152.254%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net6.0

  • 🟥 execution_time [+300.077ms; +301.790ms] or [+149.561%; +150.415%]
  • 🟩 throughput [+51936.680op/s; +56605.335op/s] or [+10.313%; +11.240%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1

  • 🟥 execution_time [+300.569ms; +303.151ms] or [+149.530%; +150.815%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net6.0

  • 🟩 execution_time [-16.416ms; -12.748ms] or [-7.633%; -5.928%]
  • 🟩 throughput [+19539.525op/s; +27024.351op/s] or [+5.360%; +7.414%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net472

  • unstable execution_time [+11.195µs; +53.499µs] or [+2.765%; +13.215%]

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

  • 🟩 allocated_mem [-19.268KB; -19.247KB] or [-7.029%; -7.021%]
  • unstable execution_time [-29.290µs; +22.758µs] or [-5.789%; +4.498%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark netcoreapp3.1

  • 🟩 allocated_mem [-17.909KB; -17.893KB] or [-6.529%; -6.523%]

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

  • unstable execution_time [+8.784µs; +13.361µs] or [+20.762%; +31.581%]
  • 🟥 throughput [-5626.396op/s; -3784.067op/s] or [-23.685%; -15.930%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark netcoreapp3.1

  • unstable execution_time [-13.521µs; -6.405µs] or [-20.978%; -9.937%]
  • 🟩 throughput [+1581.708op/s; +3091.864op/s] or [+9.704%; +18.970%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472

  • 🟥 execution_time [+302.676ms; +303.693ms] or [+152.989%; +153.503%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net6.0

  • 🟥 execution_time [+300.982ms; +303.278ms] or [+153.199%; +154.368%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+298.219ms; +300.364ms] or [+149.295%; +150.369%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net6.0

  • 🟩 throughput [+31010.656op/s; +36241.911op/s] or [+5.870%; +6.860%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net472

  • 🟥 execution_time [+298.679ms; +300.462ms] or [+148.864%; +149.753%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net6.0

  • 🟥 execution_time [+301.270ms; +302.510ms] or [+151.283%; +151.906%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+304.205ms; +306.490ms] or [+154.273%; +155.432%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net472

  • 🟥 execution_time [+299.560ms; +300.238ms] or [+149.422%; +149.760%]
  • 🟩 throughput [+66102177.481op/s; +66399143.632op/s] or [+48.140%; +48.356%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0

  • unstable execution_time [+347.982ms; +390.033ms] or [+432.778%; +485.076%]
  • 🟩 throughput [+1008.516op/s; +1182.562op/s] or [+7.796%; +9.142%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1

  • 🟥 execution_time [+299.694ms; +300.628ms] or [+149.481%; +149.947%]
  • 🟩 throughput [+18260588.051op/s; +19204269.663op/s] or [+8.088%; +8.506%]

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

  • 🟩 throughput [+98804.446op/s; +108428.255op/s] or [+9.225%; +10.124%]

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

  • 🟩 throughput [+61976.718op/s; +81549.733op/s] or [+7.174%; +9.439%]

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

  • 🟩 throughput [+94860.834op/s; +124857.013op/s] or [+7.342%; +9.664%]

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

  • 🟩 throughput [+84256.580op/s; +93919.684op/s] or [+8.368%; +9.328%]

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

  • 🟩 throughput [+45917.750op/s; +51103.746op/s] or [+8.338%; +9.280%]

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

  • 🟩 throughput [+27787.545op/s; +37513.852op/s] or [+6.220%; +8.397%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net6.0

  • 🟩 throughput [+88335.328op/s; +106411.847op/s] or [+9.869%; +11.889%]

Known flaky benchmarks without significant changes:

  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net472
  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net472
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog netcoreapp3.1
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net472
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net472
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive netcoreapp3.1
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net472
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin netcoreapp3.1

@dudikeleti
dudikeleti requested a review from jpbempel May 6, 2026 12:00

@jpbempel jpbempel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sounds legit, but I found it unfortunate to have forgot this continue.
Tests could not catch this? at least make sure we are not instrumenting this case

@dudikeleti

Copy link
Copy Markdown
Contributor Author

sounds legit, but I found it unfortunate to have forgot this continue. Tests could not catch this? at least make sure we are not instrumenting this case

I’ve only seen this in the snapshot exploration test, never in our integration tests or in customer code.

@dudikeleti
dudikeleti merged commit b281804 into master May 7, 2026
144 checks passed
@dudikeleti
dudikeleti deleted the dudik/fix-byref-like-skip-instrumentation branch May 7, 2026 13:32
@github-actions github-actions Bot added this to the vNext-v3 milestone May 7, 2026
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.

3 participants