Repository navigation
Conversation
Add J13: flag a new lock whose critical section reads, computes and writes back state that could be one immutable snapshot, and per-instance lock objects on per-span or per-trace types; suggest a CAS loop on the snapshot instead. Replacing a lock with such a CAS no longer triggers the benchmark nudge for removed locks; it is reviewed for correctness instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
🟢 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. |
…prefer-cas # Conflicts: # .agents/skills/perf-review/SKILL.md # .agents/skills/perf-review/references/checks.md
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
More details
The CAS preference retains explicit exceptions for expensive snapshot copies and blocking or non-repeatable work, alongside retry and ordering checks. The completed static review identified no actionable defects.
🤖 Bits Code Review · Commit aa8afa3
What Does This Do
Makes "prefer a compare-and-set over a lock whenever possible" part of the perf-review skill (
SKILL.md,references/checks/collections.mdandreferences/posture.md):New Java check J17: lock guarding publishable state → compare-and-set on an immutable snapshot. It flags:
synchronizedblock orReentrantLockwhose critical section only reads the current state, computes the next and writes it back (one field, or several that could form one immutable snapshot)private final Object lock = new Object()) on a per-span or per-trace typeThe suggested fix is an immutable snapshot behind one volatile field, updated by a CAS loop. J17 also tells the reviewer what to check for correctness in a lock → CAS change, and when a lock is still the right choice.
Replacing a lock with such a CAS no longer triggers the "visibly-contestable tradeoff" benchmark nudge. That nudge fires for changes that remove a lock. A lock → CAS swap now counts as adopting the preferred idiom, and is reviewed for correctness instead.
The
SKILL.mdcheck table lists J17, and notes that it's a trigger in its own right, unlike J7–J11, which only route existing findings to a fix.Motivation
Measured while replacing
PTags' per-trace sampling lock with a CAS (2026-10-22, 3 forks per arm):PTagson every JDK: no lock object or lock field.synchronizednearly free. Those JVMs are about 30% of orgs and shrinking, so the cost is accepted.From JDK 15 a monitor enter is itself a CAS on the object header, so a lock costs the atomic plus monitor bookkeeping, often plus a lock object per instance.
synchronizedalso pins virtual-thread carriers on JDK 21–23.The correctness checks in J17 come from the same change. Two mutations were tried against its stress test:
Tracked in APMLP-2100. Related: APMLP-2099 (an adaptive updater that would choose
synchronizedon biased-locking JVMs, coming) and APMLP-1838 (synchronized vs ReentrantLock under virtual threads).Additional Notes
Renumbered J13 → J17 on the sync with master. Master now uses J13 for large retained
byte[], J14 for product-off work, and the perf-review stack claims J15 and J16. The check lives inchecks/collections.md, next to the concurrency-choice guidance, since master split the oldchecks.mdinto per-topic files.Documentation-only change to the skill.
Overlaps Flag code a change carries into a hotter context, and weight header paths up (AI perf review) #12902 on one line: that PR adds bullets right above the "visibly-contestable tradeoff" clause this PR amends. Whichever merges second needs a trivial rebase.
J12 is already taken by the benchmark-validity check, so this is J13.
The
PTagslock → CAS change that motivates this will be its own PR.🤖 Generated with Claude Code