Repository navigation
fix(browser): keep up with a busy page and stay sharp on HiDPI - #982
Merged
Merged
Conversation
The window decoded every screencast frame in turn on the /events loop. A busy page sends frames faster than one decode takes, so they queued for seconds and every other event waited behind them. Four decoders now take frames at once, a page keeps only its newest frame while all four are busy, and an older frame finishing last never replaces a newer one.
An emulated device scale changes the page's devicePixelRatio but not the surface the screencast copies, so a 2x pane got 1x frames, blurred. The headless browser now launches with its scale forced to 1.5 and a pane's scale is capped there: 2x halved a busy page's frame rate.
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.
Why
On a page that animates or runs a lot of JavaScript, the session browser tab fell seconds behind the page, and the rest of the window waited with it. On a HiDPI screen the tab was also blurred.
Lag. The window decoded every screencast frame in turn on the
/eventsloop. Chrome sends the next frame on the ack, and the ack goes out once the socket takes the frame, not once the window draws it, so nothing slowed Chrome down: frames queued in the 64-event buffer while each decode ran (5 ms on a light page, 15 ms on a busy one at 1280x720), and every other event queued behind them.Blur.
SetDeviceMetricsOverridewith a scale of 2 changes the page'sdevicePixelRatio, but the screencast copies the headless browser's own surface, which stays at 1x.WithMaxWidthonly scales down, so a 2x pane got 1280x720 frames for a 2560x1440 pane.What
/eventsloop, four frames at once (frameDecoders). While all four are busy a page keeps only its newest frame, and a frame carries a sequence number so an older one finishing last never replaces a newer one.--force-device-scale-factor=1.5and a pane's scale is capped there (frameScale). A 2x pane gets 1.5x frames; a 1x pane stays 1x. The browser in its own window keeps the monitor's scale.docs/ceilings.mdnames the 1.5x cap, and no longer says frames come at the pace the window takes them.Measurements (2026-10-29, Helium headless, 1280x720 pane)
Chrome sends one frame per frame the page paints; JPEG quality and a real GPU (RTX 3050 over Vulkan instead of SwiftShader) changed nothing.
Forced device scale on that busy page: 45 fps drawn at 1x, 33 at 1.5x, 28 at 2x (forced to 2). Forcing 3 cost frames even at 1x, which is why the forced scale is the cap and not something higher.
Test plan
TestBrowserFramesDecodeTwoAtOnce,TestBrowserFrameSurplusDecodesOnlyTheNewest,TestOlderBrowserFrameDecodedLastKeepsTheNewer: 300 runs with-race; the first fails withframeDecoders = 1TestChromeScreencastDrawsAHiDPIPaneAtTheFrameScale(live Chrome): failed with a 400x300 frame for a 400x300 pane at 2x before the fix, gets 600x450 aftergofmt -l .,go vet ./...,go test ./...native/:gofmt -l .,go vet ./...,go test ./...