Skip to content

Share the WebFlux parsed-route cache across requests - #12561

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
andrea.marziali/webflux-shared-route-cache
Sep 21, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
andrea.marziali/webflux-shared-route-cache

Conversation

@amarziali

Copy link
Copy Markdown
Contributor

What Does This Do

WebFlux functional-routing instrumentation created a new parsed-route cache for every routing callback, preventing reuse across requests.

Make the cache static and bounded to 64 entries. This avoids per-callback cache allocation and lets repeated route strings reuse their parsed paths, skipping regex replacements on cache hits. Route parsing and span-tag behavior remain unchanged.

Motivation

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@amarziali
amarziali requested a review from a team as a code owner September 18, 2026 09:16
@amarziali
amarziali removed the request for review from a team September 18, 2026 09:16
@amarziali amarziali added the type: feature Enhancements and improvements label Sep 18, 2026
@amarziali
amarziali requested a review from ygree September 18, 2026 09:16
@amarziali amarziali added the inst: spring Spring instrumentation label Sep 18, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-18T09:18:36.606507Z ac38f45 PR opened
🔒 Security Review ✅ Completed 2026-09-18T09:19:53.451334Z ac38f45 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: PASS

More details

The cache uses the full route string as its key. The bounded, thread-safe cache keeps the existing route result for each key.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit ac38f45 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 58.69% (-0.41%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ac38f45 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.00 s 14.00 s [-0.7%; +0.7%] (no difference)
startup:insecure-bank:tracing:Agent 12.94 s 12.96 s [-0.8%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 17.06 s 16.82 s [+0.6%; +2.3%] (maybe worse)
startup:petclinic:iast:Agent 16.95 s 17.11 s [-1.8%; -0.1%] (maybe better)
startup:petclinic:profiling:Agent 16.69 s 16.83 s [-2.0%; +0.3%] (no difference)
startup:petclinic:sca:Agent 17.05 s 16.67 s [+1.3%; +3.3%] (significantly worse)
startup:petclinic:tracing:Agent 16.15 s 15.68 s [-0.9%; +6.9%] (no difference)

Commit: ac38f45e · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@dougqh dougqh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch.

I created a couple follow-up tasks for us to create annotations, so the perf-review checker can catch this mistake in the future.

@ygree ygree left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@amarziali

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-21 06:59:11 UTC ℹ️ Start processing command /merge


2026-09-21 06:59:17 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-09-21 07:23:06 UTC ❌ MergeQueue: The build pipeline contains failing jobs for this merge request

Build pipeline has failing jobs for 07423c6:

⚠️ Do NOT retry failed jobs directly (why?).

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.
Details

Since those jobs are not marked as being allowed to fail, the pipeline will most likely fail.
Therefore, and to allow other builds to be processed, this merge request has been rejected and the pipeline got canceled.

@amarziali

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-21 07:23:40 UTC ℹ️ Start processing command /merge


2026-09-21 07:23:45 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-09-21 08:35:38 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit b01dd8b into master Sep 21, 2026
608 of 611 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the andrea.marziali/webflux-shared-route-cache branch September 21, 2026 08:35
@github-actions github-actions Bot added this to the 1.67.0 milestone Sep 21, 2026
dougqh added a commit that referenced this pull request Sep 25, 2026
Spot-checks the annotation against the real defect it was modeled on:
PR #12561 (commit e6b8756) made this exact DDCache field static
after it lived per-instance, unshared, for ~4 years. Serves as the
first real call site for @Staticlifetime.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Oct 8, 2026
#12646)

Add @Staticlifetime and @singleton marker annotations

@Staticlifetime marks a field that must live for the whole program
rather than for its enclosing instance's lifetime (e.g. a cache
allocated per-request instead of once). @singleton is its escape
valve, declaring a class has exactly one process-wide instance, so
an instance field on it can satisfy @Staticlifetime without being
static. Wires a matching check into the perf-review checks doc,
mirroring the existing @NoEscape field-storage check.

APMLP-1846, APMLP-1847

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Add Checker contract section to @singleton javadoc

Splits narrative vs. machine-checkable rule, matching the convention
established by @NoEscape and @Staticlifetime.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Annotate WebFlux route cache with @Staticlifetime

Spot-checks the annotation against the real defect it was modeled on:
PR #12561 (commit e6b8756) made this exact DDCache field static
after it lived per-instance, unshared, for ~4 years. Serves as the
first real call site for @Staticlifetime.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Annotate UTF8 tag/value caches with @Staticlifetime

TAG_CACHE/VALUE_CACHE in TraceMapperV0_4 and KEY_CACHE/VALUE_CACHE
in OtlpCommonProto are already static final -- marking them adds
compliant-example coverage alongside RouteOnSuccessOrError's
violation-turned-compliant case.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Revert "Annotate WebFlux route cache with @Staticlifetime"

Holding off on applying @Staticlifetime to real cache fields until
@SuppressPerfContract (dougqh/perf-contract-suppress, PR #12647) lands
-- want the exemption mechanism in place before widening the annotated
surface.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Revert "Annotate UTF8 tag/value caches with @Staticlifetime"

Same reason as the WebFlux route-cache revert: hold off until
@SuppressPerfContract lands.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Close StaticLifetime checker-contract gaps: require final, static+non-final

Per Bits AI review: the contract accepted "static" fields and
singleton-scoped instance fields without requiring final, so a
mutable field of either shape could pass while still being
reassignable to a fresh, cold instance at runtime -- defeating the
amortization guarantee the annotation exists to protect, just via a
write instead of via scope. Add an explicit mutability trigger and
require final in the Accepted description for both shapes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Fix StaticLifetime's ClassValue paragraph to match its own checker contract

Per review: the intro implied a ClassValue-backed holder need not be
static itself, contradicting the Accepted list below it, which
requires "static final ClassValue<T>". Clarify that it's the
per-Class values ClassValue computes that get a free process-wide
lifetime, not the holder field referencing the ClassValue instance --
that still has to be static final.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Merge remote-tracking branch 'origin/master' into dougqh/static-lifetime-singleton

# Conflicts:
#	.agents/skills/perf-review/references/checks.md

Move StaticLifetime/Singleton into datadog.perfcontract and meta-annotate with @PerfContract

Relocates both annotations out of the legacy datadog.trace.api.function
package into the new datadog.perfcontract package (introduced by #12647),
alongside PerfContract/SuppressPerfContract, and adds @PerfContract so
tooling can discover them as perf-contract markers the same way it
already discovers Strategy/StrategyConsumer/NoEscape. No other code
references either annotation, so no import-site updates are needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Tighten the @singleton Javadoc

Applies a review suggestion: a static holder or DI registration does not by
itself guarantee a single instance, and only final instance fields satisfy
@Staticlifetime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Restructure the @Staticlifetime Javadoc around one field rule

Applies a review suggestion: a single accepted/violation/out-of-scope rule,
an accurate ClassValue note, and block examples. Keeps the note on the name
echoing Rust's 'static lifetime. Examples use <pre> with escaped @ and generics
so javadoc does not read a leading @ as a block tag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Require final for @Singleton-held fields in the perf-review StaticLifetime check

Matches the @Staticlifetime and @singleton Javadoc: only a final instance
field on a @singleton class is accepted, and ClassValue holders follow the
plain static final rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: spring Spring instrumentation type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants