Drop per-call String allocation in SharedDBCommenter.containsTraceComment#11734
Conversation
SharedDBCommenter.containsTraceComment built nine "KEY + =" strings on every call: the keys are encode()-derived (not compile-time constants), so each "KEY + =" is a runtime concat. A non-matching comment ran all nine checks and allocated nine throwaway Strings per call. Precompute the needles once at class init as *_EQ constants; the contains-chain is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Throughput benchmark at @threads(8) over a realistic comment-content mix (mostly non-DD, the all-nine-checks worst case) to surface the per-call allocation removed by hoisting the "<key>=" needles to constants. Run the parent commit (baseline) vs this branch and read the ops/s delta; -prof gc (gc.alloc.rate.norm) corroborates the mechanism. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
zulu-17 @fork(5), -prof gc: 33.5M -> 62.1M ops/s (~1.9x), 156 -> ~0 B/op. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Benchmark results (zulu-17, JDK 17.0.7,
|
| throughput | gc.alloc.rate.norm | |
|---|---|---|
| before (concat) | 33.5M ± 2.0M ops/s | 156 B/op |
after (*_EQ) |
62.1M ± 3.8M ops/s | ~0 B/op (10⁻⁵) |
Removing the per-call KEY + "=" concatenation drops allocation to ~0 and lifts throughput ~1.9× at @Threads(8) — the allocation win surfacing as throughput, exactly as intended. Benchmark Javadoc refreshed in 9426141.
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
The merge request has been interrupted because the build 1513741081229096535 took longer than expected. The current limit for the base branch 'master' is 120 minutes. |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
error while getting head build completion result DetailsError: There was an error while retrieving the result for pipeline 121199058 FullStacktrace: |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
…ment (#11734) Hoist containsTraceComment "<key>=" needles to constants SharedDBCommenter.containsTraceComment built nine "KEY + =" strings on every call: the keys are encode()-derived (not compile-time constants), so each "KEY + =" is a runtime concat. A non-matching comment ran all nine checks and allocated nine throwaway Strings per call. Precompute the needles once at class init as *_EQ constants; the contains-chain is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Add SharedDBCommenterBenchmark for containsTraceComment Throughput benchmark at @threads(8) over a realistic comment-content mix (mostly non-DD, the all-nine-checks worst case) to surface the per-call allocation removed by hoisting the "<key>=" needles to constants. Run the parent commit (baseline) vs this branch and read the ops/s delta; -prof gc (gc.alloc.rate.norm) corroborates the mechanism. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Refresh SharedDBCommenterBenchmark results to JDK 17 @fork(5) zulu-17 @fork(5), -prof gc: 33.5M -> 62.1M ops/s (~1.9x), 156 -> ~0 B/op. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Merge branch 'master' into dougqh/dbcommenter-alloc Merge branch 'master' into dougqh/dbcommenter-alloc Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
What This Does
Reduces allocation SQL comment injection, but removing unnecessary allocation during contains checks
Motivation
Reduce allocation overhead
Additional Notes
SharedDBCommenter.containsTraceCommentbuilt nineKEY + "="needle strings on every call. The keys arestatic finalbut initialized viaencode(...), so they are not compile-time constants — eachKEY + "="is a runtime concatenation. A non-matching comment ran all nine checks and allocated nine throwaway Strings per call.This hoists the needles to
*_EQconstants computed once at class init. Thecontains-chain is otherwise unchanged.Measured
SharedDBCommenterBenchmark(added here) — JDK 25,@Threads(8),@Fork(5),-prof gc:gc.alloc.rate.norm*_EQ)~1.9× throughput, allocation eliminated. Per our usual approach the allocation win is surfaced as a throughput delta at
@Threads(8)(GC is a shared-heap tax);-prof gccorroborates the mechanism (156 → 0 B/op). Numbers live in the benchmark's class Javadoc.🤖 Generated with Claude Code