Optimize PropagationTags hash/compare and pre-cache decision maker values#11119
Optimize PropagationTags hash/compare and pre-cache decision maker values#11119
Conversation
…lues TagValue.hash and TagValue.compare consumed ~3% of foreground CPU via per-character CharConverter virtual dispatch. updateKnuthSamplingRate and decision maker string concatenation added another ~2%. Inline hashDD/hashW3C and compareDD/compareW3C to eliminate interface dispatch per character. Use forType(DATADOG) once before compare loops to avoid per-character charAt() branch. Pre-cache decision maker TagValues for mechanisms 0-13 to eliminate String concatenation and cache lookup on every sampling decision. Reorder clearCachedHeader() null check to short-circuit for fresh PTags. tag: no release note tag: ai generated Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| * samplingMechanism String concatenation and TagValue.from() cache lookup on every sampling | ||
| * decision. | ||
| */ | ||
| private static final int MAX_KNOWN_MECHANISM = SamplingMechanism.AI_GUARD; // 13 |
There was a problem hiding this comment.
Currently, this would be easy for someone to forget to update.
I'd like to move this constant into SamplingMechanism.
I'd also like to add a test that checks via reflection that MAX_KNOWN_MECHANISM is equal to the highest value of any of the constant in SamplingMechanism (excluding MAX_KNOWN_MECHANISM).
Move the constant from PTagsFactory to SamplingMechanism so it stays in sync when new mechanisms are added. Add a reflective test that verifies MAX_KNOWN_MECHANISM equals the highest non-negative byte constant in the class (excluding itself). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| return start < 0 || end <= 0 || s.length() < end; | ||
| } | ||
|
|
||
| /** Hash a DD-encoded input by converting each char to W3C (the canonical form). */ |
There was a problem hiding this comment.
I'm not convinced these hash code specializations are worth the trouble. I'm curious what others think.
BenchmarksStartupParameters
See matching parameters
SummaryFound 1 performance improvements and 0 performance regressions! Performance is the same for 56 metrics, 14 unstable metrics.
Startup time reports for insecure-bankgantt
title insecure-bank - global startup overhead: candidate=1.62.0-SNAPSHOT~6d93d59e66, baseline=1.62.0-SNAPSHOT~693449b6f0f
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.066 s) : 0, 1065925
Total [baseline] (8.884 s) : 0, 8884105
Agent [candidate] (1.065 s) : 0, 1065185
Total [candidate] (8.837 s) : 0, 8836550
section iast
Agent [baseline] (1.22 s) : 0, 1220278
Total [baseline] (9.568 s) : 0, 9568353
Agent [candidate] (1.228 s) : 0, 1227673
Total [candidate] (9.544 s) : 0, 9543732
gantt
title insecure-bank - break down per module: candidate=1.62.0-SNAPSHOT~6d93d59e66, baseline=1.62.0-SNAPSHOT~693449b6f0f
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.248 ms) : 0, 1248
crashtracking [candidate] (1.24 ms) : 0, 1240
BytebuddyAgent [baseline] (636.866 ms) : 0, 636866
BytebuddyAgent [candidate] (640.349 ms) : 0, 640349
AgentMeter [baseline] (29.553 ms) : 0, 29553
AgentMeter [candidate] (29.585 ms) : 0, 29585
GlobalTracer [baseline] (251.053 ms) : 0, 251053
GlobalTracer [candidate] (249.621 ms) : 0, 249621
AppSec [baseline] (32.828 ms) : 0, 32828
AppSec [candidate] (32.111 ms) : 0, 32111
Debugger [baseline] (60.069 ms) : 0, 60069
Debugger [candidate] (59.065 ms) : 0, 59065
Remote Config [baseline] (609.864 µs) : 0, 610
Remote Config [candidate] (608.603 µs) : 0, 609
Telemetry [baseline] (8.21 ms) : 0, 8210
Telemetry [candidate] (8.845 ms) : 0, 8845
Flare Poller [baseline] (9.245 ms) : 0, 9245
Flare Poller [candidate] (7.464 ms) : 0, 7464
section iast
crashtracking [baseline] (1.228 ms) : 0, 1228
crashtracking [candidate] (1.239 ms) : 0, 1239
BytebuddyAgent [baseline] (798.248 ms) : 0, 798248
BytebuddyAgent [candidate] (803.356 ms) : 0, 803356
AgentMeter [baseline] (11.345 ms) : 0, 11345
AgentMeter [candidate] (11.582 ms) : 0, 11582
GlobalTracer [baseline] (238.538 ms) : 0, 238538
GlobalTracer [candidate] (240.938 ms) : 0, 240938
AppSec [baseline] (29.518 ms) : 0, 29518
AppSec [candidate] (31.585 ms) : 0, 31585
Debugger [baseline] (64.263 ms) : 0, 64263
Debugger [candidate] (63.38 ms) : 0, 63380
Remote Config [baseline] (529.529 µs) : 0, 530
Remote Config [candidate] (525.528 µs) : 0, 526
Telemetry [baseline] (11.176 ms) : 0, 11176
Telemetry [candidate] (9.724 ms) : 0, 9724
Flare Poller [baseline] (3.428 ms) : 0, 3428
Flare Poller [candidate] (3.497 ms) : 0, 3497
IAST [baseline] (25.621 ms) : 0, 25621
IAST [candidate] (25.658 ms) : 0, 25658
Startup time reports for petclinicgantt
title petclinic - global startup overhead: candidate=1.62.0-SNAPSHOT~6d93d59e66, baseline=1.62.0-SNAPSHOT~693449b6f0f
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.068 s) : 0, 1067798
Total [baseline] (11.119 s) : 0, 11119221
Agent [candidate] (1.061 s) : 0, 1061130
Total [candidate] (11.116 s) : 0, 11116117
section appsec
Agent [baseline] (1.25 s) : 0, 1250442
Total [baseline] (11.147 s) : 0, 11146896
Agent [candidate] (1.249 s) : 0, 1249421
Total [candidate] (11.09 s) : 0, 11090357
section iast
Agent [baseline] (1.227 s) : 0, 1226898
Total [baseline] (11.366 s) : 0, 11366201
Agent [candidate] (1.222 s) : 0, 1221842
Total [candidate] (11.263 s) : 0, 11263060
section profiling
Agent [baseline] (1.192 s) : 0, 1191854
Total [baseline] (11.008 s) : 0, 11007787
Agent [candidate] (1.187 s) : 0, 1186666
Total [candidate] (11.117 s) : 0, 11117162
gantt
title petclinic - break down per module: candidate=1.62.0-SNAPSHOT~6d93d59e66, baseline=1.62.0-SNAPSHOT~693449b6f0f
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.249 ms) : 0, 1249
crashtracking [candidate] (1.241 ms) : 0, 1241
BytebuddyAgent [baseline] (640.199 ms) : 0, 640199
BytebuddyAgent [candidate] (634.286 ms) : 0, 634286
AgentMeter [baseline] (29.847 ms) : 0, 29847
AgentMeter [candidate] (29.682 ms) : 0, 29682
GlobalTracer [baseline] (251.226 ms) : 0, 251226
GlobalTracer [candidate] (250.469 ms) : 0, 250469
AppSec [baseline] (32.761 ms) : 0, 32761
AppSec [candidate] (32.23 ms) : 0, 32230
Debugger [baseline] (60.565 ms) : 0, 60565
Debugger [candidate] (60.122 ms) : 0, 60122
Remote Config [baseline] (597.342 µs) : 0, 597
Remote Config [candidate] (607.844 µs) : 0, 608
Telemetry [baseline] (8.21 ms) : 0, 8210
Telemetry [candidate] (8.114 ms) : 0, 8114
Flare Poller [baseline] (6.706 ms) : 0, 6706
Flare Poller [candidate] (8.265 ms) : 0, 8265
section appsec
crashtracking [baseline] (1.238 ms) : 0, 1238
crashtracking [candidate] (1.214 ms) : 0, 1214
BytebuddyAgent [baseline] (662.226 ms) : 0, 662226
BytebuddyAgent [candidate] (660.604 ms) : 0, 660604
AgentMeter [baseline] (12.146 ms) : 0, 12146
AgentMeter [candidate] (12.048 ms) : 0, 12048
GlobalTracer [baseline] (249.97 ms) : 0, 249970
GlobalTracer [candidate] (250.684 ms) : 0, 250684
IAST [baseline] (24.707 ms) : 0, 24707
IAST [candidate] (24.452 ms) : 0, 24452
AppSec [baseline] (185.293 ms) : 0, 185293
AppSec [candidate] (185.46 ms) : 0, 185460
Debugger [baseline] (66.021 ms) : 0, 66021
Debugger [candidate] (66.593 ms) : 0, 66593
Remote Config [baseline] (620.711 µs) : 0, 621
Remote Config [candidate] (587.029 µs) : 0, 587
Telemetry [baseline] (8.269 ms) : 0, 8269
Telemetry [candidate] (7.797 ms) : 0, 7797
Flare Poller [baseline] (3.452 ms) : 0, 3452
Flare Poller [candidate] (3.534 ms) : 0, 3534
section iast
crashtracking [baseline] (1.228 ms) : 0, 1228
crashtracking [candidate] (1.215 ms) : 0, 1215
BytebuddyAgent [baseline] (802.251 ms) : 0, 802251
BytebuddyAgent [candidate] (798.932 ms) : 0, 798932
AgentMeter [baseline] (11.418 ms) : 0, 11418
AgentMeter [candidate] (11.363 ms) : 0, 11363
GlobalTracer [baseline] (240.442 ms) : 0, 240442
GlobalTracer [candidate] (238.845 ms) : 0, 238845
IAST [baseline] (25.887 ms) : 0, 25887
IAST [candidate] (25.395 ms) : 0, 25395
AppSec [baseline] (31.225 ms) : 0, 31225
AppSec [candidate] (31.181 ms) : 0, 31181
Debugger [baseline] (63.003 ms) : 0, 63003
Debugger [candidate] (64.741 ms) : 0, 64741
Remote Config [baseline] (1.102 ms) : 0, 1102
Remote Config [candidate] (531.815 µs) : 0, 532
Telemetry [baseline] (10.674 ms) : 0, 10674
Telemetry [candidate] (9.928 ms) : 0, 9928
Flare Poller [baseline] (3.487 ms) : 0, 3487
Flare Poller [candidate] (3.564 ms) : 0, 3564
section profiling
crashtracking [baseline] (1.179 ms) : 0, 1179
crashtracking [candidate] (1.182 ms) : 0, 1182
BytebuddyAgent [baseline] (695.649 ms) : 0, 695649
BytebuddyAgent [candidate] (691.699 ms) : 0, 691699
AgentMeter [baseline] (9.162 ms) : 0, 9162
AgentMeter [candidate] (9.124 ms) : 0, 9124
GlobalTracer [baseline] (208.328 ms) : 0, 208328
GlobalTracer [candidate] (208.108 ms) : 0, 208108
AppSec [baseline] (32.95 ms) : 0, 32950
AppSec [candidate] (32.575 ms) : 0, 32575
Debugger [baseline] (66.355 ms) : 0, 66355
Debugger [candidate] (65.469 ms) : 0, 65469
Remote Config [baseline] (588.4 µs) : 0, 588
Remote Config [candidate] (570.179 µs) : 0, 570
Telemetry [baseline] (7.954 ms) : 0, 7954
Telemetry [candidate] (7.806 ms) : 0, 7806
Flare Poller [baseline] (3.632 ms) : 0, 3632
Flare Poller [candidate] (3.548 ms) : 0, 3548
ProfilingAgent [baseline] (94.406 ms) : 0, 94406
ProfilingAgent [candidate] (95.267 ms) : 0, 95267
Profiling [baseline] (94.987 ms) : 0, 94987
Profiling [candidate] (95.836 ms) : 0, 95836
LoadParameters
See matching parameters
SummaryFound 1 performance improvements and 3 performance regressions! Performance is the same for 16 metrics, 16 unstable metrics.
Request duration reports for petclinicgantt
title petclinic - request duration [CI 0.99] : candidate=1.62.0-SNAPSHOT~6d93d59e66, baseline=1.62.0-SNAPSHOT~693449b6f0f
dateFormat X
axisFormat %s
section baseline
no_agent (19.496 ms) : 19297, 19695
. : milestone, 19496,
appsec (18.839 ms) : 18648, 19030
. : milestone, 18839,
code_origins (18.053 ms) : 17877, 18229
. : milestone, 18053,
iast (18.036 ms) : 17855, 18216
. : milestone, 18036,
profiling (18.656 ms) : 18471, 18840
. : milestone, 18656,
tracing (17.872 ms) : 17693, 18052
. : milestone, 17872,
section candidate
no_agent (19.646 ms) : 19444, 19849
. : milestone, 19646,
appsec (18.614 ms) : 18430, 18798
. : milestone, 18614,
code_origins (18.16 ms) : 17983, 18338
. : milestone, 18160,
iast (17.788 ms) : 17611, 17964
. : milestone, 17788,
profiling (18.126 ms) : 17944, 18309
. : milestone, 18126,
tracing (18.951 ms) : 18763, 19139
. : milestone, 18951,
Request duration reports for insecure-bankgantt
title insecure-bank - request duration [CI 0.99] : candidate=1.62.0-SNAPSHOT~6d93d59e66, baseline=1.62.0-SNAPSHOT~693449b6f0f
dateFormat X
axisFormat %s
section baseline
no_agent (1.234 ms) : 1222, 1246
. : milestone, 1234,
iast (3.397 ms) : 3348, 3445
. : milestone, 3397,
iast_FULL (6.142 ms) : 6081, 6204
. : milestone, 6142,
iast_GLOBAL (3.597 ms) : 3546, 3649
. : milestone, 3597,
profiling (2.065 ms) : 2045, 2084
. : milestone, 2065,
tracing (1.89 ms) : 1875, 1905
. : milestone, 1890,
section candidate
no_agent (1.241 ms) : 1229, 1253
. : milestone, 1241,
iast (3.278 ms) : 3231, 3325
. : milestone, 3278,
iast_FULL (6.025 ms) : 5964, 6085
. : milestone, 6025,
iast_GLOBAL (3.851 ms) : 3787, 3916
. : milestone, 3851,
profiling (2.067 ms) : 2049, 2085
. : milestone, 2067,
tracing (1.847 ms) : 1832, 1862
. : milestone, 1847,
DacapoParameters
See matching parameters
SummaryFound 1 performance improvements and 0 performance regressions! Performance is the same for 10 metrics, 1 unstable metrics.
Execution time for biojavagantt
title biojava - execution time [CI 0.99] : candidate=1.62.0-SNAPSHOT~6d93d59e66, baseline=1.62.0-SNAPSHOT~693449b6f0f
dateFormat X
axisFormat %s
section baseline
no_agent (14.877 s) : 14877000, 14877000
. : milestone, 14877000,
appsec (15.099 s) : 15099000, 15099000
. : milestone, 15099000,
iast (18.557 s) : 18557000, 18557000
. : milestone, 18557000,
iast_GLOBAL (18.165 s) : 18165000, 18165000
. : milestone, 18165000,
profiling (14.971 s) : 14971000, 14971000
. : milestone, 14971000,
tracing (14.884 s) : 14884000, 14884000
. : milestone, 14884000,
section candidate
no_agent (15.526 s) : 15526000, 15526000
. : milestone, 15526000,
appsec (14.785 s) : 14785000, 14785000
. : milestone, 14785000,
iast (18.044 s) : 18044000, 18044000
. : milestone, 18044000,
iast_GLOBAL (18.05 s) : 18050000, 18050000
. : milestone, 18050000,
profiling (15.415 s) : 15415000, 15415000
. : milestone, 15415000,
tracing (15.287 s) : 15287000, 15287000
. : milestone, 15287000,
Execution time for tomcatgantt
title tomcat - execution time [CI 0.99] : candidate=1.62.0-SNAPSHOT~6d93d59e66, baseline=1.62.0-SNAPSHOT~693449b6f0f
dateFormat X
axisFormat %s
section baseline
no_agent (1.482 ms) : 1470, 1493
. : milestone, 1482,
appsec (3.815 ms) : 3593, 4037
. : milestone, 3815,
iast (2.261 ms) : 2192, 2330
. : milestone, 2261,
iast_GLOBAL (2.316 ms) : 2246, 2385
. : milestone, 2316,
profiling (2.109 ms) : 2053, 2164
. : milestone, 2109,
tracing (2.071 ms) : 2018, 2125
. : milestone, 2071,
section candidate
no_agent (1.436 ms) : 1424, 1447
. : milestone, 1436,
appsec (3.8 ms) : 3579, 4021
. : milestone, 3800,
iast (2.265 ms) : 2196, 2335
. : milestone, 2265,
iast_GLOBAL (2.308 ms) : 2238, 2378
. : milestone, 2308,
profiling (2.099 ms) : 2044, 2154
. : milestone, 2099,
tracing (2.072 ms) : 2018, 2125
. : milestone, 2072,
|
Summary
hashDD()/hashW3C()to eliminateCharConvertervirtual dispatch per character inTagValuehash computationcompareDD()/compareW3C()withforType(DATADOG)pre-fetch to eliminate per-charactercharAt()branch and converter dispatchTagValueinstances for sampling mechanisms 0-13, eliminating"-" + samplingMechanismString concatenation on every sampling decisionclearCachedHeader()null check to short-circuit for fresh PTags, avoiding wasted volatile write on every trace rootTagValueCacheBenchmarkandPropagationTagsLifecycleBenchmarkJMH benchmarksMotivation: PropagationTags processing consumed ~5% of foreground CPU in a 16-thread span creation stress test — 2% from
TagValue.hashper-character virtual dispatch, 1% fromTagValue.compare, 1% fromupdateKnuthSamplingRateunnecessary header invalidation, and 1% from String allocation in decision maker construction.Benchmark results
TagValueCacheBenchmark (zero GC allocation):
PropagationTagsLifecycleBenchmark:
Test plan
*TagValue*tests pass*PropagationTags*tests pass (Datadog, W3C, DDSpanContext)*KnuthSampling*tests pass*CoreSpanBuilder*and*DDSpanContext*tests pass🤖 Generated with Claude Code