Repository navigation
perf(mac): resolve terminal names once per full process capture - #27146
Conversation
Use the host's fresh /dev directory order to translate tdev into the same tty names without retaining positive or negative device-name caches. Preserve localized start markers, argv, targeted ps columns, and failure verdicts. Fall back to canonical ps when translation is unavailable. Co-authored-by: Giorgio Zamparelli <[email protected]> Co-authored-by: out-of-place <[email protected]>
Resolve the Darwin filesystem API when used so platform-independent imports work with existing filesystem mocks. Remove the discarded non-Linux parse and keep fresh asynchronous inventory work bounded through deadline and drain. Co-authored-by: Giorgio Zamparelli <[email protected]> Co-authored-by: out-of-place <[email protected]>
Render numeric Darwin terminal devices and Linux column sets from one synthetic process table while keeping the production translator and caches. Exercise both hosts with stable filesystem identity and preserve scan, agent recognition, evidence, escalation, and exit/restart assertions. Co-authored-by: Giorgio Zamparelli <[email protected]> Co-authored-by: out-of-place <[email protected]>
Measured one asynchronous stat at a time lowers host CPU and leaves more filesystem pool capacity for other work. Preserve fresh native-order lookup and keep timed-out work held until its admitted request actually drains. Co-authored-by: Giorgio Zamparelli <[email protected]> Co-authored-by: out-of-place <[email protected]>
Use the host no-terminal marker in evidence-budget fixtures so Linux does not read proc start times after the timed ps response. Observe rejection before advancing fake timers while retaining the exact 1199ms capture-age assertion and 1201ms rejection case. Co-authored-by: Giorgio Zamparelli <[email protected]> Co-authored-by: out-of-place <[email protected]>
Record proc fixture reads outside production error handling and use deterministic numeric start ticks for Linux PID identity. Co-authored-by: Giorgio Zamparelli <[email protected]> Co-authored-by: out-of-place <[email protected]>
macOS names every pseudo-terminal ttys%03d from its minor number, with one /dev entry each. Check that one path per distinct terminal and accept it only when it is a character device with the same device number; scan /dev only for devices still unnamed, stopping once all are found. Removes the fixed per-capture /dev scan, so few-terminal hosts pay one stat per terminal and busy hosts stat each terminal once instead of every /dev entry.
- Key terminal lookups by numeric major/minor so padded tokens still resolve. - Clear the in-flight naming slot in the test reset. - Prove cancellation waits for the active stat, and compare naming with real ps output on macOS.
Give the parity check a real terminal on headless Macs and prove that pty is named by the direct lookup without scanning /dev.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No identified issue needs resolution before merging; the reported checks support proceeding with normal validation. Pre-merge checks |
|
ELI5
On a busy Mac, Orca regularly lists every running process so it can tell which terminal each process belongs to. Today
psdoes the job of turning each terminal's device number into a name likettys012, and with hundreds of terminals that alone takes about a second of CPU per refresh. This PR has Orca look up those names itself, checking each distinct terminal once per refresh. On the measured busy Mac, a refresh drops from about 950 ms to about 110 ms and uses about 90% less CPU overall.What Changed
Before: on macOS, a full process-table capture asked
psto print terminal names.pslooks up each name separately, which is slow when there are many terminal processes.After: the full macOS capture asks
psfor raw terminal device numbers instead, and Orca names them itself (darwin-terminal-names.ts,darwin-process-table-capture.ts). The rows it produces are the same named rows the existing readers already consume, so nothing downstream changes.ttysplus its minor device number, padded to three digits (minor 12 isttys012), and gives each one a single/deventry. For each distinct terminal, Orca checks only that one path. It accepts the name only if the entry is a character device with exactly the same device number./devthe way Apple's own lookup does: the first matching entry in directory order wins. The scan stops once every remaining device is named.psinstead of piling up more work./dev, Orca uses the existingpscapture with whatever time is left.Unchanged: Linux and Windows capture, the cheap and targeted captures, the 500 ms result cache, and strict/lenient parsing. The host that runs the processes still reads its own
/dev, so SSH works the same way. Remote clients still receive named rows, so there is no wire change. There are no new native modules, workers, processes, or protocol fields.Why
This builds on Giorgio Zamparelli's #24890 and out-of-place's #26985. Both contributors are credited with
Co-authored-bytrailers; keep those when squashing.Alternatives considered:
/devreads: used a bit less CPU, but one stuck system call would freeze the host process and every terminal it serves. Rejected./devon every capture: this was the PR's first version. It cost a fixed ~10 ms of Orca CPU per capture even with one terminal. The direct lookup replaced it, and the scan now runs only for devices the direct lookup can't verify./devchanges: rejected. Opening a terminal doesn't update/dev's modification time, and terminal numbers are reused, so a cache would show wrong names.Linked Issue
Fixes #24889
Supersedes #24890. Related: #26985 (a separate repaint-path change).
Visual Proof
N/A. This changes how the host captures processes, and nothing visible in the UI changes. Terminal names were checked against the existing output (see Testing).
Performance
Measured on an Apple M4 Max running macOS (Darwin 25.3) and Node 24, with about 2,240 processes, 1,007 of them attached to a terminal, across 389 terminals. Numbers are medians of warm captures using the real snapshot reader. This measures capture cost only; it is not a whole-app or battery test.
psCPUpsprints names)That table was measured with the earlier full-
/dev-scan version. The direct lookup then cut Orca's own naming time on the same Mac from about 12 ms to about 6.5 ms of CPU per capture. With a single terminal, naming dropped from about 10 ms to well under 1 ms.In a load test (100 requests over 10 seconds through the existing cache), captures finished faster, so more of them ran: 15 per window versus 6–7. Even so, combined CPU per window fell from about 7,000 ms to about 1,900 ms.
Testing
psoutput. It starts a real terminal and proves that terminal is named without scanning/dev. It also fails when the name format is deliberately broken.psexactly on two Macs. On macOS 26.3, 2,237 processes and 390 terminals. On macOS 26.6, 798 processes and 85 terminals. Every terminal on both was named by the direct lookup.All runs used
ORCA_BACKGROUND_LAUNCH=1.Review
Risk: low to medium. The production change is about 230 net lines across three modules, and most of the diff is tests. Two rounds of adversarial review found no blocking or major issues.
Trade-offs a reviewer should accept knowingly:
psused to do. On a busy Mac that's a few milliseconds per capture, against roughly 850 ms less CPU inps. With few terminals, the added cost is negligible./deventry for a terminal that sorts before the real one, Orca still shows the realttysname, wherepswould show the extra entry. A normal system never has these./devis not handled specially. On a host where device lookups are persistently slow, the capture can hit its deadline sooner and fall back to plainps. There is no backoff that remembers this between captures.Agent skill upstream boundary
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)