Repository navigation
perf(emulator): park device stream when the window is hidden - #9842
Merged
Merged
Conversation
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a React hook that tracks window visibility, recovers from stale document visibility, and delays stream parking by 500 ms. EmulatorDeviceFrame now includes effective window visibility when deciding whether to show the stream. Tests cover delayed parking, cancellation when visibility returns quickly, document visibility reset, and continued streaming when stale visibility is proven. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
The iOS MJPEG and Android scrcpy device streams are gated only on the pane being the active tab (isActive, PR #7382). When the emulator tab is frontmost but the whole Orca window is hidden/minimized/occluded/display-asleep, the full-fps pipeline keeps running: main-process socket read + JPEG/H.264 decode + IPC + renderer decode. Renderer background-throttling (#9395) cannot stop it because the pipeline is IPC-push driven from main. Gate showStream additionally on window visibility via a new occlusion-safe hook that honors the terminal stale-visibility latch (so a display-sleep occlusion wedge can't freeze the emulator on a black frame) and delays the visible->hidden park by 500ms so a quick Cmd+Tab round-trip doesn't renegotiate the device stream. Co-authored-by: Orca <[email protected]>
nwparker
force-pushed
the
nwparker/perf-14-emulator-visibility-gate
branch
from
July 22, 2026 21:15
9cfeca0 to
5720c18
Compare
This was referenced Jul 27, 2026
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…i#9842) The iOS MJPEG and Android scrcpy device streams are gated only on the pane being the active tab (isActive, PR stablyai#7382). When the emulator tab is frontmost but the whole Orca window is hidden/minimized/occluded/display-asleep, the full-fps pipeline keeps running: main-process socket read + JPEG/H.264 decode + IPC + renderer decode. Renderer background-throttling (stablyai#9395) cannot stop it because the pipeline is IPC-push driven from main. Gate showStream additionally on window visibility via a new occlusion-safe hook that honors the terminal stale-visibility latch (so a display-sleep occlusion wedge can't freeze the emulator on a black frame) and delays the visible->hidden park by 500ms so a quick Cmd+Tab round-trip doesn't renegotiate the device stream. Co-authored-by: Orca <[email protected]>
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
The iOS MJPEG and Android scrcpy emulator device streams were gated only on the pane being the active tab (
isActive, from PR #7382). When the emulator tab is frontmost but the whole Orca window is hidden/minimized/occluded/display-asleep, the full-device-fps pipeline keeps running: main-process socket read + JPEG/H.264 decode + IPC serialize + renderer decode. Renderer background-throttling (#9395) can't stop it because the pipeline is IPC-push driven from main, so an explicit source-level teardown is required.This gates
showStreamadditionally on window visibility via a new hookuseEmulatorStreamWindowVisible()that:isWindowVisible() || isDocumentVisibilityProvenStale(), reusing the terminal occlusion-staleness latch so a macOS display-sleep occlusion wedge can't freeze the emulator on a black frame with no recovery (same bug class as the 78MB terminal drop);ELI5
Your phone emulator kept live-streaming video from the device even when Orca was hidden behind other windows or your screen was asleep — decoding frames nobody could see, draining battery. Now it pauses the video when the window isn't visible and instantly resumes when you come back. It waits half a second before pausing so flicking away and back doesn't cause a reconnect stutter, and it has a safety catch so a known macOS "is it visible?" glitch after sleep can't leave you staring at a black screen.
Proof of zero regression
isActivegate uses (use-emulator-frame-stream.ts/use-emulator-video-stream.ts), so no new main-process work.isDocumentVisibilityProvenStale()+registerStaleDocumentVisibilityRecovery()— a wedgedhiddenafter display sleep is treated as visible and forces a re-render, so the stream can't be permanently parked on a wedge.canInteract, notshowStream, and the wheel-gesture flush (80ms) fires well before the 500ms park, so parking never strands a pending gesture.useSyncExternalStorestability, wedge recovery, timer cleanup on unmount/rapid-toggle, MJPEG/scrcpy clean restart (registry replays cached meta + SPS/PPS + GOP keyframe on resume), and no double-teardown whenisActiveand window-visibility flip together. No regression found.emulator-device-frame-visibility.test.tsx— 6/6 pass (3 existing + 3 new: park-after-delay + resume, no-teardown on quick hide/show within the delay, keeps streaming while hidden when occlusion is proven stale).pnpm typecheck:web: clean.Proof of perf improvement
While the emulator tab is frontmost and the window is hidden/minimized/occluded/asleep, this eliminates a continuous full-device-fps pipeline (main socket read + JPEG/H.264 decode + IPC + renderer decode). The new tests assert
stopFrameStreamis called at the source once parked (no more per-frame IPC), directly proving the frames stop. Complements PR #7382 (which covered the background-tab case); this covers the whole-window-hidden case #7382 does not.Made with Orca 🐋