Skip to content

Add @Strategy marker annotation for static-polymorphism strategies#11984

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
masterfrom
dougqh/strategy-annotation
Jul 20, 2026
Merged

Add @Strategy marker annotation for static-polymorphism strategies#11984
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
masterfrom
dougqh/strategy-annotation

Conversation

@dougqh

@dougqh dougqh commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Adds @Strategy, a marker annotation for static-polymorphism strategy types and parameters — the stateless, concrete-typed policy objects the JIT can devirtualize and inline so one shared algorithm specializes to straight-line code per caller.

Motivation

Marks where static-polymorphism approach to an API is being used.

The intention is to clearly signal when this style of API is being used.
The annotation will serve as documentation on how to get the most performance out of such an API.

And eventually, tooling will be able to check if the API is being used as intended.

Additional Notes

From Claude...

Marker-only — no enforcement yet. The discipline it names is held by hand for now; the contract lives in the javadoc.

Design notes

  • @Target({TYPE, PARAMETER}) — on a type: "this is a strategy" (hold it static final, concrete-typed, so it inlines). On a parameter: "this is a strategy slot" (the arg should be a static final constant or a non-capturing lambda). The parameter target lets us tag a slot even when its type can't be (e.g. a java.util.function.Function we don't own).
  • @Retention(SOURCE) — zero bytecode footprint, no runtime metadata (agent hygiene); a source-level checker reads it fine.
  • @Documented — the contract is human-facing, so it belongs in the generated javadoc.
  • @Inherited — documentary intent (a concrete subclass of a strategy base is a strategy); inert under SOURCE retention, kept as a signal.

Applications

None here, by design — the first uses land in the stacked FlatHashtable PR that builds on this one.

🤖 Generated with Claude Code

@dougqh dougqh added tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes comp: core Tracer core type: refactoring labels Jul 17, 2026
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 56.82% (-0.48%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 120469d | Docs | Datadog PR Page | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Jul 17, 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 13.96 s 13.94 s [-0.6%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 12.89 s 13.04 s [-2.1%; -0.3%] (maybe better)
startup:petclinic:appsec:Agent 16.81 s 16.73 s [-0.9%; +1.8%] (no difference)
startup:petclinic:iast:Agent 16.41 s 16.84 s [-6.9%; +1.7%] (no difference)
startup:petclinic:profiling:Agent 16.54 s 16.37 s [-3.5%; +5.6%] (no difference)
startup:petclinic:sca:Agent 16.81 s 16.63 s [-0.2%; +2.3%] (no difference)
startup:petclinic:tracing:Agent 15.73 s 15.68 s [-5.6%; +6.2%] (unstable)

Commit: 120469d4 · 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 force-pushed the dougqh/strategy-annotation branch from 4a05183 to fbb0085 Compare July 17, 2026 16:28
…orphism strategies

Marker-only (no enforcement yet): telegraphs the static-polymorphism strategy pattern and gives a future checker targets. @strategy marks strategy types/parameters; @StrategyConsumer marks the higher-order methods that must inline for them to specialize. Contracts live in the javadoc. Applications land in stacked PRs (FlatHashtable first).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/strategy-annotation branch from fbb0085 to da64961 Compare July 17, 2026 16:36
@dougqh dougqh mentioned this pull request Jul 19, 2026
@dougqh
dougqh marked this pull request as ready for review July 20, 2026 12:19
@dougqh
dougqh requested a review from a team as a code owner July 20, 2026 12:19
@dougqh
dougqh requested a review from mcculls July 20, 2026 12:19

@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

Two marker annotations for static-polymorphism strategies: @strategy (for types/parameters) and @StrategyConsumer (for methods). Both use SOURCE retention, require no runtime behavior, and contain no enforcement. Compilation, metaannotations, and javadoc are correct; no uses yet (by design). Zero behavioral or bytecode impact — this is a documentation-first pattern telegraph.

Was this helpful? React 👍 or 👎

📊 Validated against 5 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit da64961 · What is Autotest? · Any feedback? Reach out in #autotest

Comment thread internal-api/src/main/java/datadog/trace/api/function/Strategy.java Outdated
Address review: describe 'static polymorphism' directly in the annotation
rather than referring to FlatHashtable, which is a consumer of @strategy — the
reference was a conceptual back-reference that left the base annotation unable to
stand on its own.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* -XX:+PrintInlining}.
*/
@Documented
@Inherited

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.

@Inherited has no affect on source-only annotations, so this could be dropped

(it also has no affect on parameter annotations - it's only really useful on class annotations: https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Inherited.html)

@dougqh dougqh Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I thought about that. Ultimately, I decided to keep it to show the intent -- that the concept transfers from parent to child -- including abstract child classes.

@mcculls mcculls 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.

Interested to see where this goes

@dougqh

dougqh commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Interested to see where this goes

@mcculls If you are curious to see usage, you can look at #11980 where the first Strategy and StrategyConsumer are located.

I'm also going to try figure out a way to update the perf-review to check for this, but I'm not quite sure what that will look like yet.

@dougqh
dougqh enabled auto-merge July 20, 2026 18:39
@dougqh
dougqh added this pull request to the merge queue Jul 20, 2026
@dd-octo-sts

dd-octo-sts Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jul 20, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-20 19:27:03 UTC ℹ️ Start processing command /merge


2026-07-20 19:27:08 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-07-20 20:25:27 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 20, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit a059d47 into master Jul 20, 2026
587 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dougqh/strategy-annotation branch July 20, 2026 20:25
@github-actions github-actions Bot added this to the 1.65.0 milestone Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants