Repository navigation
perf(gateway): avoid expanding audience scopes on cache hits - #184829
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis 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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR copies connection scopes into retained audience-key facts only on cache misses. Example: Alice retains scopes ["operator.read"] across three session events under the same sharing revision.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR removes measurable allocation work with a focused change, and no actionable correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway sharing preparer turns current recipient identity, policy, scopes, and publication revision into an audience key used to share session-event presentation work. flowchart LR
A[Session event] --> B[Current recipient sharing facts]
B --> C[Revision and viewer key cache]
C --> D[Audience presentation]
D --> E[WebSocket broadcast]
Technical reviewBest possible solution: Retain this focused optimization within the existing revision-and-viewer cache owner. Do we have a high-confidence way to reproduce the issue? The pinned base expands connection scopes before checking for a retained-key hit, establishing the unnecessary work directly in source; no target code was executed during this review. Is this the best way to solve the issue? The patch is the smallest complete fix: compare live scopes against the existing snapshot and construct the expanded snapshot only when replacing it. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cd3bcc017653. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +6, Tests +27. Total +33 across 2 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 26, 2026, 1:27 PM ET / 17:27 UTC. |
What Problem This Solves
Session-event audience-key cache hits still copy connection scopes into a newly grown facts array for every recipient, after the key itself has already been cached.
User Impact
Lower allocation during session-event fanout, with unchanged key bytes, visibility decisions, live authority inputs, and invalidation. No configuration or migration is required.
Why This Change Was Made
Compare the existing retained snapshot against fixed facts and live scope values directly; append scopes to a new snapshot only on a miss. This preserves the existing revision/viewer cache owner and every scope value, including the distinction between absent and empty scopes. It introduces no additional cache or lifetime.
Production delta: +6 lines (11 additions, 5 removals). The small growth separates live scope comparison from miss-only snapshot construction while preserving the existing authority contract. The author simplification pass retained only this change and one regression; broadcaster serialization already shares projection payloads and is untouched.
Evidence
The earlier sharing-key reuse change (#184201,
24fa04ed3f78) is an ancestor of evidence builde8764a3f; this removes residual work rather than repeating that fix. Baseline for the measurements isc00af62f03e6ab9929234a998693f53341a4e126.Acceptance: unchanged key/authorization digest, lower owner allocation, no controlled material CPU regression. Existing committed workload:
scripts/perf/session-sharing-key-measure.ts, with 65 interleaved clients, eight identities, 40 plugin entries, 10,000 synthetic session targets, and sharing-revision changes every 100 events. Each arm runs 3,000 events / 195,000 lookups, after 200 warmup events. Node v26.12.1, macOS; timing and sampled allocation are separate passes.All output digests match. Allocation improves in every pair (−8.08% to −10.24%). Timing pairs are −2.57%, −4.45%, +36.41%, −8.44%, −7.83%, +1.58%; the sixth pair was the predeclared extra pair after mixed signs. No sample was excluded. The signed absolute CPU mean is +3.890 ms per 195,000 lookups, below the 20% adverse threshold; this is an allocation win, not a CPU speedup claim. Host one-minute load ranged 11.47–22.40 on baseline timing arms and 11.54–23.21 on candidate timing arms; allocation arms ranged 20.70–25.33 and 21.71–23.92 respectively.
Reproduce with
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/session-sharing-key-measure.ts; use--allocationsfor the separate allocation pass and--owner src/gateway/.session-sharing-read-base.tsfor the saved baseline module. The script header documents this workflow; no shared perf README changes.session-sharing.prepared.test.ts: 3/3 passed, 0.52 s test time, 38.89 s wrapper wall time (compiler setup dominates). CI confirms the same three tests passed in 0.625 s (18 ms regression, 529 ms profile lifecycle, 78 ms prepared authorization). Existing merge-alias, role-policy, identity-detachment, and no-SQL checks remain green.session-sharing.events.test.ts,session-row-presentation.test.ts,server-broadcast.serialization.test.ts: 25/25 passed; 74.78 s wrapper wall time. Includes live revocation, recipient isolation, exact wire/sequence behavior, and real WebSocket compression coverage.git diff --checkpassed.Scope/gaps: this follows the authorized duplicate-work fast path. No whole-Gateway load/stress campaign, GC/loop/list latency claim, or Team mutation. CI run 40366493863 passed on exact head
89beb13d7ddcfedb7e3ab9460b12ea5f38b39312(35m28s including runner queues; no reruns). Build artifacts, selected Node/UI tests, type checks, lint, boundary checks, and baseline ratchets passed. The GitHub Codex review also completed on that head with no findings. This PR is ready for the coordinating maintainer to review and merge; this lane does not self-merge.