Skip to content

Find code that uses perf-contract annotations before reviewing (AI perf review) - #13382

Open
dougqh wants to merge 8 commits into
dougqh/perf-review-check-formatfrom
dougqh/perf-review-contract-lookup
Open

dougqh wants to merge 8 commits into
dougqh/perf-review-check-formatfrom
dougqh/perf-review-contract-lookup

Conversation

@dougqh

@dougqh dougqh commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #13376 ("Rewrite perf-review checks in a Flag / Not when format (AI perf review)"), which is stacked on #13375 and #13373. Merge those first.

What does this PR do?

The performance-contract checks (#8 @NoEscape, #9 @StaticLifetime, #10 @BackgroundOnly) fire on code that never names the annotation. Examples are a field whose type is @NoEscape, or a call into a class marked @BackgroundOnly. Until now the reviewer had to notice those on its own, and contracts.md listed the @NoEscape types by hand. That list was already stale: it was missing TagMap.Internals.

Step 1b in SKILL.md now runs tooling/contract_lookup.py, which prints three lists:

  1. Marked elements. Each contract annotation and the type, field or method it marks, plus the types @ImpliedFor lists on StaticLifetime and their subtypes (QualifiedClassNameCache, Codec and others extend ClassValue). Only files that import the contract annotations count, so javax.inject.Singleton in the Play smoke tests is left out.
  2. One hop. Class-level fields and methods declared with a marked type, for example TraceMapperV0_4.TAG_CACHE (a SimpleUtf8Cache). Methods only match when qualified by their declaring class (SubSequence.of(), because names like of() and next() are everywhere.
  3. Non-comment lines that use either list, tagged with the name that matched: the diff's added lines, or every line of the files given with --paths for a direct review. In those files, a call through a local or parameter of a marked type (cache.getUtf8(...)) counts too.

The reviewer checks every line in list 3 against contracts.md, however large the diff is. A hit is a place to look, not a finding. The lookup reads the working tree by default, including uncommitted edits, so it covers the same code as Step 1; --rev scans a commit instead.

The lookup is a standard-library Python script rather than a shell snippet in SKILL.md, so an agent runs one short command and its behavior doesn't depend on the shell. tooling/tests/test_contract_lookup.py builds a small fixture repository and covers implied subtypes, annotated fields, calls through locals and parameters, uncommitted edits versus --rev, and --paths. A new test-perf-review-tooling CI job runs it.

contracts.md drops its hand-kept lists and points at the lookup. #10 gains two rules:

  • stay silent when a call can't be resolved to a marked type with confidence (only the method name matches, or the call goes through an unmarked interface);
  • a flag-as-measure finding, whose foreground is only inferred, stays at its base level instead of taking the per-span-core raise.

How was this checked?

The fixture tests above cover the lookup itself. On this repository, the script's output matches the earlier bash version's line for line.

The blind cross-check can't test this, because its reviewers have no repository. Instead, with the earlier bash version of the lookup, I made three throwaway local probe commits (not pushed) and reviewed each with this skill and with #13376's skill, two reviewers each, with the repository available.

Probe Expected Lookup output Lookup skill Previous skill
Diff names the marked types (stores TagMap.Internals in a field, calls SimpleUtf8Cache per span) #8 and #10 the relevant lines 2 of 2 2 of 2
Marked type reached only through a field (TAG_CACHE.getUtf8), plus a call through the unmarked EncodingCache interface #10; silent on the interface the one TAG_CACHE line 2 of 2 2 of 2
Two TAG_CACHE calls in a 1,580-line diff: one on the application thread, one on the serializer thread #10 on the first only exactly the 4 TAG_CACHE lines 2 of 2 2 of 2

What changed:

  • Every lookup reviewer got to the finding the same way: marked type, then holder, then diff line. The previous-skill reviewers found the annotations by improvising their own git grep.
  • The Track 3rd party licenses #10 level is now consistent. Lookup reviewers all reported P2. Previous-skill reviewers split between P1 and P2 for the same code.

What this does not yet show is a reviewer missing a contract use that the lookup catches. In the third probe, the 1,570 re-added lines were byte-identical to an earlier commit, so every reviewer skipped them and the real change was 10 lines. The case this is meant for, a large diff of genuinely new code, is still untested.

The lookup found nothing in the 1,570 lines of real code it scanned, apart from the planted calls. Before restricting method matches to qualified calls, of and next gave 77 false matches on the same diff.

Limits

  • One hop only. A holder of a holder, or a value passed through an interface, isn't listed. That matches Track 3rd party licenses #10's contract, which covers direct calls only.
  • Instance-method holders (methods that return a marked type, called on an instance) only match when qualified by their class, so tags.internals() is missed. The TagMap.Internals field declaration that refactoring skel #8 checks is still found.
  • Short field names can still match by accident. Each hit has to pass the check's Flag line before it becomes a finding.

Follow-ups

  • A bytecode-precise lookup, if grep proves too loose. Every use in a class file names the owner class and full member signature, for example invokevirtual SimpleUtf8Cache.getUtf8 or getstatic TraceMapperV0_4.TAG_CACHE:LSimpleUtf8Cache;. Running javap -c -p on the changed classes would find uses with no name collisions and handle tags.internals(). It needs compiled, current classes, so it would be a preferred path with this grep lookup as the fallback.
  • The intended end state is still Error Prone checkers for refactoring skel #8–Track 3rd party licenses #10, as roadmap.md notes. They see the same resolved types at compile time and make this lookup unnecessary.

🤖 Generated with Claude Code

@dougqh dougqh added tag: no release notes Changes to exclude from release notes type: refactoring comp: tooling Build & Tooling tag: ai generated Largely based on code generated by an AI or LLM labels Nov 11, 2026
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 60.60% (+0.00%)

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

@dd-octo-sts

dd-octo-sts Bot commented Nov 11, 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.05 s 13.99 s [-0.4%; +1.2%] (no difference)
startup:insecure-bank:tracing:Agent 12.89 s 13.05 s [-1.9%; -0.5%] (maybe better)
startup:petclinic:appsec:Agent 17.16 s 16.98 s [+0.1%; +2.1%] (maybe worse)
startup:petclinic:iast:Agent 17.13 s 16.98 s [+0.1%; +1.7%] (maybe worse)
startup:petclinic:profiling:Agent 16.76 s 16.88 s [-1.9%; +0.4%] (no difference)
startup:petclinic:sca:Agent 17.17 s 17.05 s [-0.0%; +1.5%] (no difference)
startup:petclinic:tracing:Agent 16.20 s 15.72 s [-1.4%; +7.6%] (no difference)

Commit: 05868bd2 · 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 marked this pull request as ready for review November 11, 2026 21:17
@dougqh
dougqh requested a review from a team as a code owner November 11, 2026 21:17
@dougqh
dougqh requested review from cecile75 and removed request for a team November 11, 2026 21:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T21:24:45.866915Z 069041b Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 069041b1e0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .agents/skills/perf-review/SKILL.md Resolved
Comment thread .agents/skills/perf-review/SKILL.md Resolved
Comment thread .agents/skills/perf-review/SKILL.md Resolved
Comment thread .agents/skills/perf-review/SKILL.md Resolved
Comment thread .agents/skills/perf-review/SKILL.md Resolved

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

Bits Code Review: FAIL

The required lookup silently misses explicitly annotated fields, ClassValue subtypes, and uncommitted contract uses. These omissions can leave contract violations out of the reviewer’s checklist.

Open Bits AI session

🤖 Bits Code Review · Commit 069041b

Comment thread .agents/skills/perf-review/SKILL.md Resolved
Comment thread .agents/skills/perf-review/SKILL.md Resolved
Comment thread .agents/skills/perf-review/SKILL.md Resolved
@dougqh
dougqh force-pushed the dougqh/perf-review-check-format branch from 70572f7 to a3284cc Compare November 18, 2026 17:41
@dougqh
dougqh requested a review from a team as a code owner November 18, 2026 17:41
@dougqh
dougqh requested review from AlexeyKuznetsov-DD and removed request for a team November 18, 2026 17:41
@dougqh
dougqh force-pushed the dougqh/perf-review-contract-lookup branch from 069041b to 9f3af05 Compare November 18, 2026 18:03

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

Bits Code Review: FAIL

The required contract lookup omits staged and unstaged changes and fails to recognize subclasses of implied contract types such as ClassValue, leaving relevant declarations outside its mandatory review list.

Open Bits AI session

🤖 Bits Code Review · Commit 9f3af05

Comment thread .agents/skills/perf-review/SKILL.md Resolved
Comment thread .agents/skills/perf-review/SKILL.md Resolved
@dougqh
dougqh force-pushed the dougqh/perf-review-check-format branch from 4b608c0 to c339477 Compare November 19, 2026 17:59
@dougqh
dougqh force-pushed the dougqh/perf-review-contract-lookup branch from 9f3af05 to 30dd6d3 Compare November 19, 2026 17:59

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

Bits Code Review: FAIL

The lookup silently skips staged and unstaged changes covered by the main workflow, and it omits ClassValue subclasses covered by the static-lifetime contract.

Open Bits AI session

🤖 Bits Code Review · Commit 30dd6d3

Comment thread .agents/skills/perf-review/SKILL.md Resolved
Comment thread .agents/skills/perf-review/SKILL.md Resolved
The contract checks (#8-#10) fire on code that never names the annotation,
and contracts.md listed the @NoEscape types by hand. That list was already
stale: it was missing TagMap.Internals.

Step 1b in SKILL.md now runs a lookup that prints:
1. each contract annotation and the type or method it marks, including the
   types @ImpliedFor lists, from files that import the annotations (so
   javax.inject.Singleton and similar are left out);
2. class-level fields and methods declared with a marked type, one hop;
   methods only match when qualified by their declaring class, since names
   like of() and next() are everywhere;
3. the added, non-comment lines of the diff that use either list.

The reviewer checks every line in list 3 against contracts.md. It runs under
bash explicitly, since it relies on word splitting.

contracts.md drops its hand-kept lists, and #10 gains two rules: stay silent
when a call can't be resolved to a marked type with confidence, and don't
raise a flag-as-measure finding for the per-span core when its foreground is
only inferred.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/perf-review-check-format branch from c339477 to df28da1 Compare November 20, 2026 14:33
@dougqh
dougqh force-pushed the dougqh/perf-review-contract-lookup branch from 30dd6d3 to 01d5bda Compare November 20, 2026 14:33

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

Bits Code Review: FAIL

The lookup silently omits local Java edits included in the main review and fields declared with subclasses of implied-contract types. These omissions leave relevant contract checks dependent on incidental manual discovery.

Open Bits AI session

🤖 Bits Code Review · Commit 01d5bda

Comment thread .agents/skills/perf-review/SKILL.md Resolved
Comment thread .agents/skills/perf-review/SKILL.md Resolved
The lookup now reads the working tree by default, as Step 1 does, and
takes REV for a commit or PATHS for a direct review of files. It also:
- expands the @ImpliedFor types to their subtypes;
- recognizes annotated fields, including annotations on the same line;
- matches calls through locals and parameters of marked types in the
  files under review.

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

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

Bits Code Review: FAIL

The PR adds repository-based performance-contract discovery, and this update fixes the earlier omissions of uncommitted edits and implied-type subclasses. One issue remains in direct-file reviews: setting both REV and PATHS discovers contracts from the selected commit but scans working-tree contents, which can omit the intended code.

Open Bits AI session

🤖 Bits Code Review · Commit 67fa53e

Comment thread .agents/skills/perf-review/SKILL.md Resolved
tooling/contract_lookup.py replaces the bash in SKILL.md Step 1b, with
the same three lists and --rev / --paths / --diff-base options. Fixture
tests cover the cases review found: implied subtypes, annotated fields,
calls through locals and parameters, uncommitted edits, and file mode.
A CI job runs them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh requested a review from a team as a code owner November 20, 2026 16:07
@dougqh
dougqh requested review from randomanderson and removed request for a team November 20, 2026 16:07

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

Bits Code Review: PASS

More details

The supplied revision covers the lookup gaps discussed in human review, including working-tree edits, implied subtypes, annotated fields, and local receivers. No actionable defect was identified through static inspection; execution remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 2410649

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

Bits Code Review: FAIL

The PR adds contract-usage discovery and CI coverage, addressing earlier snapshot and discovery gaps. One confirmed issue remains: diff.noprefix=true makes the lookup silently omit all added-line hits; a localized suggestion forcing stable Git prefixes was verified against the reproduced failure.

Open Bits AI session

🤖 Bits Code Review · Commit 364f2fc

Comment thread tooling/contract_lookup.py Resolved
dougqh and others added 2 commits November 23, 2026 10:57
With diff.noprefix, color.diff=always or an external diff, the "+++ b/"
headers the lookup parses change and list 3 came back empty. The diff
now passes explicit prefixes, --no-color and --no-ext-diff. A test sets
diff.noprefix and color.diff in the fixture repo.

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

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

Bits Code Review: PASS

More details

The PR adds contract-usage discovery, review guidance, and CI coverage while addressing earlier snapshot and discovery gaps. The reported Git-prefix issue is fixed: added contract uses remain visible with diff.noprefix enabled and forced color, and no findings remain open.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 05868bd

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD 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.

I left a suggestion for running the lookup and its tests as Java 25 source files, along with three cases where the current lookup misses candidates.

Comment thread .gitlab-ci.yml
stage: tests
needs: []
script:
- python3 -m unittest discover -s tooling/tests -p 'test_contract_lookup.py'

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.

Could we move the lookup and its fixture tests to Java source launchers, following .gitlab/collect-result/CollectResults.java? Java 25 can run both the lookup and a sibling test entry point directly with java File.java, so the skill and CI can keep a one-command invocation with no Gradle build or separate compilation step. CI can use the tooling JDK through the existing .gitlab/java-utils.sh resolver.

The main benefit would be using JavacTask.parse() to read annotations, fields, and supertypes across line breaks. It can parse source without resolving the project's dependencies. We could keep Git for revision selection and diff ranges, and use Java's syntax trees for declaration discovery.

decl = declaration_pattern(types, "=;(")
decl_re = re.compile(posix_to_python(decl))
fields, methods = set(), set()
pattern = rf"(public|protected|private|static)[^=;(]*(^|[^A-Za-z0-9_.]){decl}"

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.

Could the holder lookup include package-private instance fields? In a fixture with final Cache encodingCache and static final Cache SHARED_CACHE, the lookup surfaced Holder.SHARED_CACHE.encode() but omitted holder.encodingCache.encode() from the same @ForegroundSafe method in another file. Both calls directly reach the marked cache type. The modifier requirement here excludes the first field. I'd add this pair as a regression test.

declaration = re.compile(r"\b(?:class|interface)\s+(\w+)")
while new:
names = "|".join(sorted(new))
pattern = (r"(class|interface)[[:space:]]+[A-Za-z0-9_]+[^{;]*(extends|implements)[^{;]*"

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.

The earlier subtype fix now catches same-line declarations. I reproduced a remaining case where class SplitNames and extends ClassValue<String> are on separate lines. An added field of type SplitNames stayed out of list 3, while a same-line control appeared. Could we cover this layout in the fixture suite and discover the full declaration? This is one case where the Java parser would help.

yield path, number, line
return
path, number = None, 0
for line in source.diff(base, MAIN).splitlines():

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.

Could we use a file-level scan when a diff removes a contract exemption? I tried removing only @Singleton from a class with a final instance field of a ClassValue subtype. The field then falls under check #9, but the branch scan returned no candidates because the hunk has no added lines. Scanning the same file with --paths surfaced the field.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: tooling Build & Tooling 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