Optimize template/matrix variable merging in spring-webmvc#11144
Draft
Optimize template/matrix variable merging in spring-webmvc#11144
Conversation
…ation Replace eager HashMap copy + PairList allocations with a lazy MergedMapView that defers the merge until first iteration. Add empty-map short-circuits to skip merge logic entirely when template or matrix vars are empty (the common case). This reduces per-request allocations in the spring-webmvc AppSec path for both 3.1 and 6.0 instrumentations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
BenchmarksStartupParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 63 metrics, 8 unstable metrics. Startup time reports for insecure-bankgantt
title insecure-bank - global startup overhead: candidate=1.62.0-SNAPSHOT~791954d163, baseline=1.62.0-SNAPSHOT~3fb37337ab
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.065 s) : 0, 1064792
Total [baseline] (8.875 s) : 0, 8874849
Agent [candidate] (1.065 s) : 0, 1065368
Total [candidate] (8.847 s) : 0, 8847088
section iast
Agent [baseline] (1.238 s) : 0, 1238482
Total [baseline] (9.582 s) : 0, 9582272
Agent [candidate] (1.24 s) : 0, 1239988
Total [candidate] (9.638 s) : 0, 9637955
gantt
title insecure-bank - break down per module: candidate=1.62.0-SNAPSHOT~791954d163, baseline=1.62.0-SNAPSHOT~3fb37337ab
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.259 ms) : 0, 1259
crashtracking [candidate] (1.229 ms) : 0, 1229
BytebuddyAgent [baseline] (638.068 ms) : 0, 638068
BytebuddyAgent [candidate] (637.898 ms) : 0, 637898
AgentMeter [baseline] (29.628 ms) : 0, 29628
AgentMeter [candidate] (29.551 ms) : 0, 29551
GlobalTracer [baseline] (250.748 ms) : 0, 250748
GlobalTracer [candidate] (250.468 ms) : 0, 250468
AppSec [baseline] (32.967 ms) : 0, 32967
AppSec [candidate] (32.596 ms) : 0, 32596
Debugger [baseline] (60.09 ms) : 0, 60090
Debugger [candidate] (59.569 ms) : 0, 59569
Remote Config [baseline] (607.47 µs) : 0, 607
Remote Config [candidate] (590.274 µs) : 0, 590
Telemetry [baseline] (8.219 ms) : 0, 8219
Telemetry [candidate] (8.142 ms) : 0, 8142
Flare Poller [baseline] (6.766 ms) : 0, 6766
Flare Poller [candidate] (9.035 ms) : 0, 9035
section iast
crashtracking [baseline] (1.239 ms) : 0, 1239
crashtracking [candidate] (1.254 ms) : 0, 1254
BytebuddyAgent [baseline] (810.581 ms) : 0, 810581
BytebuddyAgent [candidate] (813.306 ms) : 0, 813306
AgentMeter [baseline] (11.672 ms) : 0, 11672
AgentMeter [candidate] (11.7 ms) : 0, 11700
GlobalTracer [baseline] (242.034 ms) : 0, 242034
GlobalTracer [candidate] (241.36 ms) : 0, 241360
IAST [baseline] (26.186 ms) : 0, 26186
IAST [candidate] (26.854 ms) : 0, 26854
AppSec [baseline] (32.564 ms) : 0, 32564
AppSec [candidate] (33.113 ms) : 0, 33113
Debugger [baseline] (64.136 ms) : 0, 64136
Debugger [candidate] (62.201 ms) : 0, 62201
Remote Config [baseline] (558.076 µs) : 0, 558
Remote Config [candidate] (557.566 µs) : 0, 558
Telemetry [baseline] (9.43 ms) : 0, 9430
Telemetry [candidate] (9.489 ms) : 0, 9489
Flare Poller [baseline] (3.526 ms) : 0, 3526
Flare Poller [candidate] (3.639 ms) : 0, 3639
Startup time reports for petclinicgantt
title petclinic - global startup overhead: candidate=1.62.0-SNAPSHOT~791954d163, baseline=1.62.0-SNAPSHOT~3fb37337ab
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.07 s) : 0, 1069668
Total [baseline] (11.094 s) : 0, 11093912
Agent [candidate] (1.075 s) : 0, 1075098
Total [candidate] (11.102 s) : 0, 11102165
section appsec
Agent [baseline] (1.253 s) : 0, 1253466
Total [baseline] (11.13 s) : 0, 11130187
Agent [candidate] (1.251 s) : 0, 1251455
Total [candidate] (11.119 s) : 0, 11119499
section iast
Agent [baseline] (1.223 s) : 0, 1222906
Total [baseline] (11.377 s) : 0, 11376692
Agent [candidate] (1.227 s) : 0, 1226693
Total [candidate] (11.338 s) : 0, 11338382
section profiling
Agent [baseline] (1.189 s) : 0, 1188698
Total [baseline] (11.021 s) : 0, 11020601
Agent [candidate] (1.184 s) : 0, 1184133
Total [candidate] (11.114 s) : 0, 11114322
gantt
title petclinic - break down per module: candidate=1.62.0-SNAPSHOT~791954d163, baseline=1.62.0-SNAPSHOT~3fb37337ab
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.236 ms) : 0, 1236
crashtracking [candidate] (1.231 ms) : 0, 1231
BytebuddyAgent [baseline] (638.565 ms) : 0, 638565
BytebuddyAgent [candidate] (642.723 ms) : 0, 642723
AgentMeter [baseline] (29.903 ms) : 0, 29903
AgentMeter [candidate] (29.873 ms) : 0, 29873
GlobalTracer [baseline] (252.123 ms) : 0, 252123
GlobalTracer [candidate] (252.191 ms) : 0, 252191
AppSec [baseline] (32.868 ms) : 0, 32868
AppSec [candidate] (32.912 ms) : 0, 32912
Debugger [baseline] (60.625 ms) : 0, 60625
Debugger [candidate] (60.67 ms) : 0, 60670
Remote Config [baseline] (598.099 µs) : 0, 598
Remote Config [candidate] (606.297 µs) : 0, 606
Telemetry [baseline] (8.181 ms) : 0, 8181
Telemetry [candidate] (8.246 ms) : 0, 8246
Flare Poller [baseline] (9.092 ms) : 0, 9092
Flare Poller [candidate] (10.161 ms) : 0, 10161
section appsec
crashtracking [baseline] (1.228 ms) : 0, 1228
crashtracking [candidate] (1.226 ms) : 0, 1226
BytebuddyAgent [baseline] (662.906 ms) : 0, 662906
BytebuddyAgent [candidate] (663.602 ms) : 0, 663602
AgentMeter [baseline] (12.207 ms) : 0, 12207
AgentMeter [candidate] (12.165 ms) : 0, 12165
GlobalTracer [baseline] (250.687 ms) : 0, 250687
GlobalTracer [candidate] (249.052 ms) : 0, 249052
AppSec [baseline] (186.221 ms) : 0, 186221
AppSec [candidate] (185.343 ms) : 0, 185343
Debugger [baseline] (66.297 ms) : 0, 66297
Debugger [candidate] (66.336 ms) : 0, 66336
Remote Config [baseline] (608.346 µs) : 0, 608
Remote Config [candidate] (618.718 µs) : 0, 619
Telemetry [baseline] (8.425 ms) : 0, 8425
Telemetry [candidate] (8.46 ms) : 0, 8460
Flare Poller [baseline] (3.574 ms) : 0, 3574
Flare Poller [candidate] (3.505 ms) : 0, 3505
IAST [baseline] (24.732 ms) : 0, 24732
IAST [candidate] (24.613 ms) : 0, 24613
section iast
crashtracking [baseline] (1.226 ms) : 0, 1226
crashtracking [candidate] (1.213 ms) : 0, 1213
BytebuddyAgent [baseline] (799.389 ms) : 0, 799389
BytebuddyAgent [candidate] (802.498 ms) : 0, 802498
AgentMeter [baseline] (11.386 ms) : 0, 11386
AgentMeter [candidate] (11.449 ms) : 0, 11449
GlobalTracer [baseline] (239.016 ms) : 0, 239016
GlobalTracer [candidate] (239.56 ms) : 0, 239560
AppSec [baseline] (29.652 ms) : 0, 29652
AppSec [candidate] (31.229 ms) : 0, 31229
Debugger [baseline] (65.858 ms) : 0, 65858
Debugger [candidate] (64.396 ms) : 0, 64396
Remote Config [baseline] (558.196 µs) : 0, 558
Remote Config [candidate] (544.325 µs) : 0, 544
Telemetry [baseline] (9.429 ms) : 0, 9429
Telemetry [candidate] (9.378 ms) : 0, 9378
Flare Poller [baseline] (3.54 ms) : 0, 3540
Flare Poller [candidate] (3.564 ms) : 0, 3564
IAST [baseline] (26.683 ms) : 0, 26683
IAST [candidate] (26.603 ms) : 0, 26603
section profiling
ProfilingAgent [baseline] (94.449 ms) : 0, 94449
ProfilingAgent [candidate] (94.491 ms) : 0, 94491
crashtracking [baseline] (1.195 ms) : 0, 1195
crashtracking [candidate] (1.185 ms) : 0, 1185
BytebuddyAgent [baseline] (694.191 ms) : 0, 694191
BytebuddyAgent [candidate] (690.572 ms) : 0, 690572
AgentMeter [baseline] (9.082 ms) : 0, 9082
AgentMeter [candidate] (9.115 ms) : 0, 9115
GlobalTracer [baseline] (207.376 ms) : 0, 207376
GlobalTracer [candidate] (207.182 ms) : 0, 207182
AppSec [baseline] (33.02 ms) : 0, 33020
AppSec [candidate] (32.808 ms) : 0, 32808
Debugger [baseline] (65.845 ms) : 0, 65845
Debugger [candidate] (65.471 ms) : 0, 65471
Remote Config [baseline] (579.668 µs) : 0, 580
Remote Config [candidate] (576.387 µs) : 0, 576
Telemetry [baseline] (7.79 ms) : 0, 7790
Telemetry [candidate] (7.756 ms) : 0, 7756
Flare Poller [baseline] (3.575 ms) : 0, 3575
Flare Poller [candidate] (3.515 ms) : 0, 3515
Profiling [baseline] (95.017 ms) : 0, 95017
Profiling [candidate] (95.05 ms) : 0, 95050
LoadParameters
See matching parameters
SummaryFound 1 performance improvements and 0 performance regressions! Performance is the same for 17 metrics, 18 unstable metrics.
Request duration reports for insecure-bankgantt
title insecure-bank - request duration [CI 0.99] : candidate=1.62.0-SNAPSHOT~791954d163, baseline=1.62.0-SNAPSHOT~3fb37337ab
dateFormat X
axisFormat %s
section baseline
no_agent (1.24 ms) : 1228, 1251
. : milestone, 1240,
iast (3.339 ms) : 3289, 3389
. : milestone, 3339,
iast_FULL (6.247 ms) : 6181, 6312
. : milestone, 6247,
iast_GLOBAL (3.756 ms) : 3692, 3819
. : milestone, 3756,
profiling (2.129 ms) : 2109, 2150
. : milestone, 2129,
tracing (1.871 ms) : 1854, 1887
. : milestone, 1871,
section candidate
no_agent (1.228 ms) : 1217, 1239
. : milestone, 1228,
iast (3.457 ms) : 3408, 3505
. : milestone, 3457,
iast_FULL (6.319 ms) : 6253, 6385
. : milestone, 6319,
iast_GLOBAL (3.741 ms) : 3678, 3803
. : milestone, 3741,
profiling (2.397 ms) : 2374, 2419
. : milestone, 2397,
tracing (1.925 ms) : 1908, 1942
. : milestone, 1925,
Request duration reports for petclinicgantt
title petclinic - request duration [CI 0.99] : candidate=1.62.0-SNAPSHOT~791954d163, baseline=1.62.0-SNAPSHOT~3fb37337ab
dateFormat X
axisFormat %s
section baseline
no_agent (18.041 ms) : 17857, 18224
. : milestone, 18041,
appsec (18.338 ms) : 18156, 18519
. : milestone, 18338,
code_origins (17.928 ms) : 17749, 18107
. : milestone, 17928,
iast (19.384 ms) : 19187, 19581
. : milestone, 19384,
profiling (18.124 ms) : 17946, 18302
. : milestone, 18124,
tracing (17.954 ms) : 17777, 18131
. : milestone, 17954,
section candidate
no_agent (18.089 ms) : 17904, 18275
. : milestone, 18089,
appsec (18.656 ms) : 18467, 18845
. : milestone, 18656,
code_origins (18.128 ms) : 17951, 18306
. : milestone, 18128,
iast (18.345 ms) : 18162, 18527
. : milestone, 18345,
profiling (17.948 ms) : 17771, 18125
. : milestone, 17948,
tracing (18.174 ms) : 17995, 18353
. : milestone, 18174,
DacapoParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 10 metrics, 2 unstable metrics. Execution time for tomcatgantt
title tomcat - execution time [CI 0.99] : candidate=1.62.0-SNAPSHOT~791954d163, baseline=1.62.0-SNAPSHOT~3fb37337ab
dateFormat X
axisFormat %s
section baseline
no_agent (1.486 ms) : 1475, 1498
. : milestone, 1486,
appsec (3.863 ms) : 3639, 4087
. : milestone, 3863,
iast (2.3 ms) : 2230, 2370
. : milestone, 2300,
iast_GLOBAL (2.331 ms) : 2260, 2401
. : milestone, 2331,
profiling (2.504 ms) : 2286, 2722
. : milestone, 2504,
tracing (2.097 ms) : 2043, 2151
. : milestone, 2097,
section candidate
no_agent (1.495 ms) : 1483, 1507
. : milestone, 1495,
appsec (3.86 ms) : 3635, 4085
. : milestone, 3860,
iast (2.292 ms) : 2221, 2362
. : milestone, 2292,
iast_GLOBAL (2.333 ms) : 2262, 2404
. : milestone, 2333,
profiling (2.113 ms) : 2057, 2168
. : milestone, 2113,
tracing (2.094 ms) : 2040, 2149
. : milestone, 2094,
Execution time for biojavagantt
title biojava - execution time [CI 0.99] : candidate=1.62.0-SNAPSHOT~791954d163, baseline=1.62.0-SNAPSHOT~3fb37337ab
dateFormat X
axisFormat %s
section baseline
no_agent (15.098 s) : 15098000, 15098000
. : milestone, 15098000,
appsec (14.738 s) : 14738000, 14738000
. : milestone, 14738000,
iast (18.339 s) : 18339000, 18339000
. : milestone, 18339000,
iast_GLOBAL (18.015 s) : 18015000, 18015000
. : milestone, 18015000,
profiling (14.857 s) : 14857000, 14857000
. : milestone, 14857000,
tracing (14.919 s) : 14919000, 14919000
. : milestone, 14919000,
section candidate
no_agent (15.684 s) : 15684000, 15684000
. : milestone, 15684000,
appsec (15.012 s) : 15012000, 15012000
. : milestone, 15012000,
iast (18.637 s) : 18637000, 18637000
. : milestone, 18637000,
iast_GLOBAL (18.219 s) : 18219000, 18219000
. : milestone, 18219000,
profiling (14.854 s) : 14854000, 14854000
. : milestone, 14854000,
tracing (14.973 s) : 14973000, 14973000
. : milestone, 14973000,
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
templateVarsormatrixVarsis an empty Map, skip the merge entirely (biggest win — most requests don't have matrix variables)new HashMap<>(map)copy with a lazyMergedMapViewwrapper that defers the actual merge until iteration is neededget()/containsKey()work without triggering the full mergeTemplateAndMatrixVariablesInstrumentation) and 6.0 (HandleMatchAdvice)Motivation: When both template and matrix variables are present, the code copied the entire template variables map into a new
HashMapand then iterated matrix variables creatingPairListobjects for key collisions. This happened eagerly even when the merged map was only used for point lookups downstream.Files changed
TemplateAndMatrixVariablesInstrumentation.java(3.1) — empty-map short-circuits + MergedMapViewHandleMatchAdvice.java(6.0) — sameTemplateAndMatrixVariablesInstrumentation.java(6.0) — registered MergedMapView as helperMergedMapView.java(3.1, new) — lazy-merging Map implementationMergedMapView.java(6.0, new) — same for 6.0 packageTest plan
tag: no release note
tag: ai generated
🤖 Generated with Claude Code