Skip to content

Cache static and per-connection DBM comment fragments#11151

Draft
dougqh wants to merge 1 commit intomasterfrom
dougqh/cache-dbm-comment
Draft

Cache static and per-connection DBM comment fragments#11151
dougqh wants to merge 1 commit intomasterfrom
dougqh/cache-dbm-comment

Conversation

@dougqh
Copy link
Copy Markdown
Contributor

@dougqh dougqh commented Apr 17, 2026

Summary

  • Caches URL-encoded static values (service name, env, version) at first use instead of re-encoding on every query
  • Caches per-connection comment fragments (dbService, hostname, dbName) in a bounded ConcurrentHashMap keyed by connection tuple
  • Pre-sizes StringBuilder using cached fragment lengths instead of growing from zero
  • Automatically invalidates caches when Config is rebuilt (test environments)

Motivation: SharedDBCommenter.buildComment() called URLEncoder.encode("UTF-8") for immutable values (service name, env, version) on every single query execution when DBM comment injection is enabled. A new StringBuilder was allocated per call with repeated Config.get() lookups for static configuration.

Design

Three-tier caching:

  1. Connection prefix (per-DBInfo, cached in ConcurrentHashMap): ddps, dddbs, ddh, dddb
  2. Static suffix (agent-lifetime, cached in volatile String): dde, ddpv
  3. Dynamic values (per-call, never cached): ddprs, traceparent, ddsh

Test plan

  • All JDBC tests pass (317/318, 1 pre-existing Docker infra failure)
  • SharedDBCommenterForkedTest passes
  • MongoDBMCommentTest passes
  • Run full CI suite

tag: no release note
tag: ai generated

🤖 Generated with Claude Code

…enter

Eliminate repeated URLEncoder.encode() calls and StringBuilder allocation
on every query execution when DBM comment injection is enabled. The static
config values (service name, env, version) and per-connection values
(dbService, hostname, dbName) are now cached and reused across calls. Only
truly dynamic values (traceParent, peerService, baseHash) are computed
per-call. Config identity is tracked so caches auto-invalidate if Config
is rebuilt (e.g. in tests).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant