Adding lighter String processing methods to Strings#10640
Adding lighter String processing methods to Strings#10640
Conversation
- fast replaceAll for a fixed string & replacement, 3x throughput compared to regex based solutions, 1/2x allocation compared to regex solutions - added SubSequence which provides a view into a subsequence of a String without incurring extra allocation - Strings.spliit returns an Iterable<SubSequence> can be used to do light weight processing of a String
BenchmarksStartupParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 64 metrics, 7 unstable metrics. Startup time reports for insecure-bankgantt
title insecure-bank - global startup overhead: candidate=1.60.0-SNAPSHOT~a149be6159, baseline=1.60.0-SNAPSHOT~be0482d740
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.064 s) : 0, 1064190
Total [baseline] (8.753 s) : 0, 8753159
Agent [candidate] (1.063 s) : 0, 1063032
Total [candidate] (8.744 s) : 0, 8743521
section iast
Agent [baseline] (1.228 s) : 0, 1228434
Total [baseline] (9.407 s) : 0, 9407457
Agent [candidate] (1.235 s) : 0, 1235249
Total [candidate] (9.376 s) : 0, 9376224
gantt
title insecure-bank - break down per module: candidate=1.60.0-SNAPSHOT~a149be6159, baseline=1.60.0-SNAPSHOT~be0482d740
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.213 ms) : 0, 1213
crashtracking [candidate] (1.216 ms) : 0, 1216
BytebuddyAgent [baseline] (627.92 ms) : 0, 627920
BytebuddyAgent [candidate] (627.809 ms) : 0, 627809
AgentMeter [baseline] (29.097 ms) : 0, 29097
AgentMeter [candidate] (29.015 ms) : 0, 29015
GlobalTracer [baseline] (257.887 ms) : 0, 257887
GlobalTracer [candidate] (257.463 ms) : 0, 257463
AppSec [baseline] (32.935 ms) : 0, 32935
AppSec [candidate] (32.873 ms) : 0, 32873
Debugger [baseline] (62.85 ms) : 0, 62850
Debugger [candidate] (62.043 ms) : 0, 62043
Remote Config [baseline] (618.104 µs) : 0, 618
Remote Config [candidate] (611.598 µs) : 0, 612
Telemetry [baseline] (11.598 ms) : 0, 11598
Telemetry [candidate] (9.028 ms) : 0, 9028
Flare Poller [baseline] (3.764 ms) : 0, 3764
Flare Poller [candidate] (6.878 ms) : 0, 6878
section iast
crashtracking [baseline] (1.201 ms) : 0, 1201
crashtracking [candidate] (1.21 ms) : 0, 1210
BytebuddyAgent [baseline] (793.901 ms) : 0, 793901
BytebuddyAgent [candidate] (798.889 ms) : 0, 798889
AgentMeter [baseline] (11.269 ms) : 0, 11269
AgentMeter [candidate] (11.301 ms) : 0, 11301
GlobalTracer [baseline] (246.809 ms) : 0, 246809
GlobalTracer [candidate] (247.821 ms) : 0, 247821
AppSec [baseline] (31.53 ms) : 0, 31530
AppSec [candidate] (33.804 ms) : 0, 33804
Debugger [baseline] (68.259 ms) : 0, 68259
Debugger [candidate] (66.182 ms) : 0, 66182
Remote Config [baseline] (546.176 µs) : 0, 546
Remote Config [candidate] (536.626 µs) : 0, 537
Telemetry [baseline] (8.563 ms) : 0, 8563
Telemetry [candidate] (8.646 ms) : 0, 8646
Flare Poller [baseline] (3.484 ms) : 0, 3484
Flare Poller [candidate] (3.52 ms) : 0, 3520
IAST [baseline] (26.735 ms) : 0, 26735
IAST [candidate] (27.116 ms) : 0, 27116
Startup time reports for petclinicgantt
title petclinic - global startup overhead: candidate=1.60.0-SNAPSHOT~a149be6159, baseline=1.60.0-SNAPSHOT~be0482d740
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.067 s) : 0, 1067317
Total [baseline] (10.936 s) : 0, 10935911
Agent [candidate] (1.073 s) : 0, 1072785
Total [candidate] (11.027 s) : 0, 11027338
section appsec
Agent [baseline] (1.24 s) : 0, 1240374
Total [baseline] (11.01 s) : 0, 11010448
Agent [candidate] (1.24 s) : 0, 1239859
Total [candidate] (10.947 s) : 0, 10946776
section iast
Agent [baseline] (1.233 s) : 0, 1232983
Total [baseline] (11.195 s) : 0, 11194539
Agent [candidate] (1.232 s) : 0, 1232104
Total [candidate] (11.166 s) : 0, 11166210
section profiling
Agent [baseline] (1.196 s) : 0, 1195731
Total [baseline] (10.902 s) : 0, 10901853
Agent [candidate] (1.192 s) : 0, 1191595
Total [candidate] (10.978 s) : 0, 10977732
gantt
title petclinic - break down per module: candidate=1.60.0-SNAPSHOT~a149be6159, baseline=1.60.0-SNAPSHOT~be0482d740
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.195 ms) : 0, 1195
crashtracking [candidate] (1.219 ms) : 0, 1219
BytebuddyAgent [baseline] (628.425 ms) : 0, 628425
BytebuddyAgent [candidate] (631.758 ms) : 0, 631758
AgentMeter [baseline] (29.202 ms) : 0, 29202
AgentMeter [candidate] (29.246 ms) : 0, 29246
GlobalTracer [baseline] (258.004 ms) : 0, 258004
GlobalTracer [candidate] (259.089 ms) : 0, 259089
AppSec [baseline] (33.004 ms) : 0, 33004
AppSec [candidate] (32.996 ms) : 0, 32996
Debugger [baseline] (66.193 ms) : 0, 66193
Debugger [candidate] (66.443 ms) : 0, 66443
Remote Config [baseline] (616.111 µs) : 0, 616
Remote Config [candidate] (607.133 µs) : 0, 607
Telemetry [baseline] (9.982 ms) : 0, 9982
Telemetry [candidate] (9.954 ms) : 0, 9954
Flare Poller [baseline] (4.503 ms) : 0, 4503
Flare Poller [candidate] (5.261 ms) : 0, 5261
section appsec
crashtracking [baseline] (1.2 ms) : 0, 1200
crashtracking [candidate] (1.199 ms) : 0, 1199
BytebuddyAgent [baseline] (657.775 ms) : 0, 657775
BytebuddyAgent [candidate] (658.97 ms) : 0, 658970
AgentMeter [baseline] (11.943 ms) : 0, 11943
AgentMeter [candidate] (11.913 ms) : 0, 11913
GlobalTracer [baseline] (258.777 ms) : 0, 258777
GlobalTracer [candidate] (257.864 ms) : 0, 257864
AppSec [baseline] (168.3 ms) : 0, 168300
AppSec [candidate] (168.144 ms) : 0, 168144
Debugger [baseline] (66.905 ms) : 0, 66905
Debugger [candidate] (66.514 ms) : 0, 66514
Remote Config [baseline] (656.852 µs) : 0, 657
Remote Config [candidate] (659.584 µs) : 0, 660
Telemetry [baseline] (9.531 ms) : 0, 9531
Telemetry [candidate] (9.38 ms) : 0, 9380
Flare Poller [baseline] (3.776 ms) : 0, 3776
Flare Poller [candidate] (3.654 ms) : 0, 3654
IAST [baseline] (25.46 ms) : 0, 25460
IAST [candidate] (25.434 ms) : 0, 25434
section iast
crashtracking [baseline] (1.2 ms) : 0, 1200
crashtracking [candidate] (1.189 ms) : 0, 1189
BytebuddyAgent [baseline] (796.636 ms) : 0, 796636
BytebuddyAgent [candidate] (795.912 ms) : 0, 795912
AgentMeter [baseline] (11.293 ms) : 0, 11293
AgentMeter [candidate] (11.27 ms) : 0, 11270
GlobalTracer [baseline] (247.727 ms) : 0, 247727
GlobalTracer [candidate] (247.435 ms) : 0, 247435
AppSec [baseline] (34.857 ms) : 0, 34857
AppSec [candidate] (35.887 ms) : 0, 35887
Debugger [baseline] (65.381 ms) : 0, 65381
Debugger [candidate] (64.743 ms) : 0, 64743
Remote Config [baseline] (550.176 µs) : 0, 550
Remote Config [candidate] (538.62 µs) : 0, 539
Telemetry [baseline] (8.691 ms) : 0, 8691
Telemetry [candidate] (8.62 ms) : 0, 8620
Flare Poller [baseline] (3.422 ms) : 0, 3422
Flare Poller [candidate] (3.44 ms) : 0, 3440
IAST [baseline] (27.056 ms) : 0, 27056
IAST [candidate] (26.992 ms) : 0, 26992
section profiling
crashtracking [baseline] (1.202 ms) : 0, 1202
crashtracking [candidate] (1.165 ms) : 0, 1165
BytebuddyAgent [baseline] (684.576 ms) : 0, 684576
BytebuddyAgent [candidate] (681.302 ms) : 0, 681302
AgentMeter [baseline] (8.577 ms) : 0, 8577
AgentMeter [candidate] (8.546 ms) : 0, 8546
GlobalTracer [baseline] (216.103 ms) : 0, 216103
GlobalTracer [candidate] (216.082 ms) : 0, 216082
AppSec [baseline] (32.629 ms) : 0, 32629
AppSec [candidate] (32.532 ms) : 0, 32532
Debugger [baseline] (67.375 ms) : 0, 67375
Debugger [candidate] (67.443 ms) : 0, 67443
Remote Config [baseline] (641.08 µs) : 0, 641
Remote Config [candidate] (644.212 µs) : 0, 644
Telemetry [baseline] (9.083 ms) : 0, 9083
Telemetry [candidate] (9.192 ms) : 0, 9192
Flare Poller [baseline] (3.806 ms) : 0, 3806
Flare Poller [candidate] (3.788 ms) : 0, 3788
ProfilingAgent [baseline] (100.69 ms) : 0, 100690
ProfilingAgent [candidate] (100.17 ms) : 0, 100170
Profiling [baseline] (101.268 ms) : 0, 101268
Profiling [candidate] (100.742 ms) : 0, 100742
LoadParameters
See matching parameters
SummaryFound 0 performance improvements and 3 performance regressions! Performance is the same for 17 metrics, 16 unstable metrics.
Request duration reports for insecure-bankgantt
title insecure-bank - request duration [CI 0.99] : candidate=1.60.0-SNAPSHOT~a149be6159, baseline=1.60.0-SNAPSHOT~be0482d740
dateFormat X
axisFormat %s
section baseline
no_agent (1.187 ms) : 1175, 1198
. : milestone, 1187,
iast (3.13 ms) : 3088, 3172
. : milestone, 3130,
iast_FULL (5.825 ms) : 5766, 5883
. : milestone, 5825,
iast_GLOBAL (3.479 ms) : 3421, 3536
. : milestone, 3479,
profiling (2.115 ms) : 2096, 2133
. : milestone, 2115,
tracing (1.782 ms) : 1768, 1796
. : milestone, 1782,
section candidate
no_agent (1.189 ms) : 1178, 1200
. : milestone, 1189,
iast (3.234 ms) : 3191, 3277
. : milestone, 3234,
iast_FULL (6.055 ms) : 5993, 6116
. : milestone, 6055,
iast_GLOBAL (3.581 ms) : 3519, 3642
. : milestone, 3581,
profiling (2.091 ms) : 2072, 2110
. : milestone, 2091,
tracing (1.778 ms) : 1764, 1793
. : milestone, 1778,
Request duration reports for petclinicgantt
title petclinic - request duration [CI 0.99] : candidate=1.60.0-SNAPSHOT~a149be6159, baseline=1.60.0-SNAPSHOT~be0482d740
dateFormat X
axisFormat %s
section baseline
no_agent (19.422 ms) : 19220, 19623
. : milestone, 19422,
appsec (18.852 ms) : 18660, 19045
. : milestone, 18852,
code_origins (17.574 ms) : 17400, 17749
. : milestone, 17574,
iast (18.072 ms) : 17890, 18255
. : milestone, 18072,
profiling (18.268 ms) : 18087, 18449
. : milestone, 18268,
tracing (17.779 ms) : 17600, 17957
. : milestone, 17779,
section candidate
no_agent (19.53 ms) : 19330, 19729
. : milestone, 19530,
appsec (19.666 ms) : 19464, 19867
. : milestone, 19666,
code_origins (17.393 ms) : 17223, 17563
. : milestone, 17393,
iast (17.629 ms) : 17455, 17803
. : milestone, 17629,
profiling (18.792 ms) : 18603, 18982
. : milestone, 18792,
tracing (17.935 ms) : 17755, 18115
. : milestone, 17935,
DacapoParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 11 metrics, 1 unstable metrics. Execution time for tomcatgantt
title tomcat - execution time [CI 0.99] : candidate=1.60.0-SNAPSHOT~a149be6159, baseline=1.60.0-SNAPSHOT~be0482d740
dateFormat X
axisFormat %s
section baseline
no_agent (1.473 ms) : 1461, 1484
. : milestone, 1473,
appsec (3.795 ms) : 3572, 4018
. : milestone, 3795,
iast (2.256 ms) : 2186, 2325
. : milestone, 2256,
iast_GLOBAL (2.3 ms) : 2230, 2369
. : milestone, 2300,
profiling (2.112 ms) : 2055, 2169
. : milestone, 2112,
tracing (2.053 ms) : 2000, 2107
. : milestone, 2053,
section candidate
no_agent (1.467 ms) : 1456, 1479
. : milestone, 1467,
appsec (3.76 ms) : 3540, 3980
. : milestone, 3760,
iast (2.253 ms) : 2184, 2322
. : milestone, 2253,
iast_GLOBAL (2.294 ms) : 2225, 2364
. : milestone, 2294,
profiling (2.082 ms) : 2027, 2136
. : milestone, 2082,
tracing (2.066 ms) : 2013, 2120
. : milestone, 2066,
Execution time for biojavagantt
title biojava - execution time [CI 0.99] : candidate=1.60.0-SNAPSHOT~a149be6159, baseline=1.60.0-SNAPSHOT~be0482d740
dateFormat X
axisFormat %s
section baseline
no_agent (15.143 s) : 15143000, 15143000
. : milestone, 15143000,
appsec (14.702 s) : 14702000, 14702000
. : milestone, 14702000,
iast (18.645 s) : 18645000, 18645000
. : milestone, 18645000,
iast_GLOBAL (17.939 s) : 17939000, 17939000
. : milestone, 17939000,
profiling (15.14 s) : 15140000, 15140000
. : milestone, 15140000,
tracing (14.823 s) : 14823000, 14823000
. : milestone, 14823000,
section candidate
no_agent (15.734 s) : 15734000, 15734000
. : milestone, 15734000,
appsec (14.99 s) : 14990000, 14990000
. : milestone, 14990000,
iast (18.119 s) : 18119000, 18119000
. : milestone, 18119000,
iast_GLOBAL (17.681 s) : 17681000, 17681000
. : milestone, 17681000,
profiling (15.24 s) : 15240000, 15240000
. : milestone, 15240000,
tracing (14.684 s) : 14684000, 14684000
. : milestone, 14684000,
|
These benchmarks exist to show why the APIs are forbidden
| * StringReplacementBenchmark.string_replaceAll thrpt 6 14611046.391 ± 4865682.875 ops/s | ||
| * StringReplacementBenchmark.string_replaceAll:gc.alloc.rate thrpt 6 11391.346 ± 3790.917 MB/sec | ||
| * |
There was a problem hiding this comment.
Can you add also String.replace(CharSequence, CharSequence) for completeness?
There was a problem hiding this comment.
Good catch. I'd overlooked that replace actually does a replace all, so I didn't realize it was equivalent.
There was a problem hiding this comment.
To my surprise, the Strings.replaceAll that implemented is actually still 20% faster than String.replace.
What Does This Do
Adds to StringUtils
Motivation
In subsequent PRs, these will be used to reduce allocation from String processing throughout dd-trace-java
The first focus area for improvement is QueryObfuscator
Additional Notes
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]
Note: Once your PR is ready to merge, add it to the merge queue by commenting
/merge./merge -ccancels the queue request./merge -f --reason "reason"skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.