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.
Contributor
🟢 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. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Does This Do
Makes "prefer a compare-and-set over a lock whenever possible" part of the perf-review skill (
SKILL.mdandreferences/checks.md):New Java check J13: 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. J13 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.mdsummary lists J13, 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 J13 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
PTagslock → CAS change that motivates this will be its own PR.🤖 Generated with Claude Code