Skip to content

Reuse event byte sizes when relay watchers notify several clients - #24558

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-relay-watcher-shared-sizing-20261001
Oct 3, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-relay-watcher-shared-sizing-20261001

Conversation

@nwparker

@nwparker nwparker commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​260 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​260
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

ELI5

When several clients watch the same folder, Orca works out the shared event sizes once. Each client still gets its own correctly sized messages.

What Changed

Relay watcher output already shared event grouping and measurement, but rebuilt the same ordered size array for every client needing chunks. That array now lives on the existing per-call sizing object. Per-client capacity, chunk boundaries, order, sequence/ACK fields, overflow/resync, admission and errors remain unchanged.

Why

Events are copied into private plain records and the shared grouping/measurement are immutable during one synchronous emit. Reusing only their numeric sizes avoids extra Map lookups and array construction without sharing client frames or introducing a persistent cache. Whole-batch and unused paths still avoid this work.

Linked Issue

Internal performance audit; no pre-existing issue.

Visual Proof

N/A — internal preparation changes; diagnostics or published watcher frames remain identical.

Testing

5000events over3chunking clients: measured-event lookups15000->5000 for POSIX, Windows drive and UNC paths;2fresh1000event emits4000->2000. Complete raw frames match an independent maximal-capacity encoder before count checks. Frozen stock4count regressions fail/5compatibility controls pass. Author76tests/6suites and independent96distincttests/8suites pass, covering framing, admission, overflow/oversized events, synchronous detachment, errors, setup/shutdown and settlement/drain. tc:node and full pnpm tc, scopedlint/format, changed-code quality and Electron Vite build pass on macOS.

All test launches used ORCA_BACKGROUND_LAUNCH=1.

  • Automated operation-count and output compatibility tests added
  • Physical platform/end-to-end runs (gaps below)

Review

Independent audit_renderer review approved the final two file hashes, independently reproduced stock count failures and reviewed output, freshness and failure boundaries.

Agent skill upstream boundary

  • Not applicable; no upstream skill material changed.

Notes

CI currently rejects three unchanged terminal write-spy fixture lines on main. #24600 repairs that separate fixture; rerun against the repaired base before merging this PR.

Invariant: exact ordered per-client watcher publications and unchanged wire/capacity/overflow ownership. Pure sizing reuse adds no poll, timer, query, grouping, transport event or threshold. Nearest runtime-files.watcher-process-isolation lifecycle/publication portions covered; full physical watcher fault/Electron gate is an accepted gap for this pure numeric-array change. Runtime-flavored folder paths covered; folder workspaces need no Git. Native Linux/Windows, live SSH/WSL/mixed peers, physical mobile and soak remain gaps. No latency claim.

Checklist

  • Small, focused change with ELI5 and before/after evidence
  • Visual proof N/A explained
  • Independently reviewed for correctness and performance
  • Cross-platform, SSH/remote and folder-workspace impact considered
  • Full platform CI (local focused checks passed)

Current review and integration

Reapplied only this PR’s reviewed files on main 53f9ea, preserving all newer main changes. Independent code review approves the exact scope as Low risk and found no regression or negative user-facing trade-off. Existing successful controls and new stock-negative tests are recorded in the review; fresh revised-head CI is required before merge.

The current-main controls pass 133 tests, plus full Node and supported mobile app typechecks. Existing generated assets were borrowed unchanged for compiler inputs; no install, generation or build ran. Physical native/remote/device and overall CPU/heap claims remain outside this validation.

Review-bot follow-up

This is an internal repository-maintainer audit; the pull-request template exempts maintainers from opening needless issues and from external-contributor AI disclosure. The automatic docstring-coverage suggestion is declined under AGENTS.md’s concise non-obvious-comments policy. Actual code/test findings are addressed with regression controls.

@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Optimizes event byte size calculation in relay watcher.

The PR appears safe to merge; no actionable issue was identified.

Summary

The PR reuses an ordered event-byte array across clients chunking the same watcher batch, while keeping per-client capacity and publication decisions separate.

  • Adds frame-compatibility and lookup-count tests across POSIX, Windows-drive, and UNC paths.
  • Covers fresh emits, whole batches, oversized events, detachment, and early errors.

Reviews (1) · Last reviewed commit: "Reuse event byte sizes when relay watche..."

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 72c5a0a0-94cb-4b1b-a1a2-c1aa292b4a1d

📥 Commits

Reviewing files that changed from the base of the PR and between c9a9b8d and 1c46cba.

📒 Files selected for processing (2)
  • src/relay/relay-watcher-event-emitter.ts
  • src/relay/relay-watcher-shared-byte-index.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

The relay watcher batch publisher now caches grouped event byte sizes on the batch sizing object and reuses them across clients. New tests check lookup counts and emitted frames across root styles and client capacities. They also cover oversized events, client detachment, publication errors, and closed roots.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 1c46c

The change can proceed through normal merge checks; no concrete issue with watcher frames or cached sizing remains identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: reusing event byte sizes across relay watcher clients.
Description check ✅ Passed The description covers the change, motivation, testing, visual-proof exception, review, and known validation gaps. It also explains that no linked issue is available for this internal maintainer chang…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

✅ No new issues found.

Reviewed changes

  • Share the ordered byte array across chunking clients — watcherBatchSizing gains an optional groupedEventBytes?: number[] (relay-watcher-event-emitter.ts:15-19), lazily built from the memoized grouped grouping via sizing.groupedEventBytes ??= grouped.map(...) (:135-137) and reused by every client that takes the chunking path, instead of remapping for each client.
  • Compatibility test coverage — new relay-watcher-shared-byte-index.test.ts asserts exact Map.prototype.get lookup counts and full frame bytes against an independent maximal-capacity encoder across POSIX, Windows drive, and UNC roots, plus ordering, per-emit rebuild, oversized-event, synchronous-detach, error, and short-circuit cases.

The optimization is sound: grouped and eventBytes are memoized once per emitRelayWatcherEvents call and never mutated during the synchronous emit, per-event sizes are capacity-independent, and sizing is call-local so nothing persists across emits. Whole-batch and unused paths still skip measurement. The tests are a genuine oracle rather than a mirror of the implementation's arithmetic, and the exact lookup-count assertions would fail without the change.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Store the existing grouped numeric byte-size array on the already call-local watcher batch sizing object, for reuse by later chunking clients.
@nwparker
nwparker force-pushed the nwparker/perf-relay-watcher-shared-sizing-20261001 branch from 1c46cba to 9ac4fa1 Compare October 3, 2026 06:54
@nwparker
nwparker merged commit 0afc7b1 into main Oct 3, 2026
51 checks passed
nwparker added a commit that referenced this pull request Oct 3, 2026
…24962)

* fix(opencode): bind legacy attach status to its TUI pane

Adapt the official v1 TUI API to the existing pane reporter and learn structural session identity only after execution-host admission. Preserve known creators, gate new reports to capable hosts, and register the legacy TUI entry without changing user settings or overlay targets.

Credit werlang for the same-directory investigation in #