Skip to content

feat(producer): add an auto value for PRODUCER_FORCE_SCREENSHOT - #9116

Closed
jrusso1020 wants to merge 3 commits into
mainfrom
capture-auto-screenshot
Closed

jrusso1020 wants to merge 3 commits into
mainfrom
capture-auto-screenshot

Conversation

@jrusso1020

@jrusso1020 jrusso1020 commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

What

PRODUCER_FORCE_SCREENSHOT takes a third value, auto: capture as false does (BeginFrame where it is available), except that a render whose page holds a WebGL or WebGPU canvas is captured by screenshot when GL is software. Unset, true and false behave as before.

Why

On software GL, BeginFrame capture of a page with a WebGL canvas is slower per frame than screenshot capture, while for a plain DOM page BeginFrame is the faster of the two. A host that sets false to keep BeginFrame for DOM pages pays for it on WebGL pages. auto picks per render.

Measured on one host with software GL, 12 s at 1080p, the build before this change (ms per frame, BeginFrame / screenshot): DOM page 4.3 / 11.2, WebGL page 78 / 49. So the expected gain for a WebGL page is about 1.6x. Two limits on that number: it has not been measured with this build yet, and a second host with software GL reads 34 for the same WebGL page, so about 1.4x of the difference between the two hosts remains that this change does not address. There is no measurement of the same pages on any other kind of host.

Related work

None open.

How

  • resolveConfig reads auto as the same opt-out of the software-GL screenshot clamp that false is, and marks the config (screenshotForAcceleratedCanvas).
  • The probe stage, once the page is open, asks the canvas tracker that every compiled page already carries whether a canvas in the document took a WebGL or WebGPU context. If so it reopens its browser in screenshot mode, the same step the existing first-frame fallback takes, and reports acceleratedCanvasScreenshot.
  • An in-process render follows that report the way it follows the first-frame fallback. A distributed plan writes it to the encoder record that every chunk reads, so chunks never decide for themselves.

Known cost and limits:

  • With auto on software GL the probe browser is opened for every render, including one that would otherwise have skipped it. The added time has not been measured yet; it will be measured on a short render before any host is switched to auto.
  • Only canvases attached to the page's own document after its first load are looked at. A canvas created later in the timeline, one never attached to the document (drawn off-page and copied into a 2D canvas), and one inside a shadow root are not seen; that render stays on BeginFrame as with false. A canvas handed to an OffscreenCanvas is seen.
  • If the tracker is absent from the page the answer is "no canvas", which keeps today's false behaviour.
  • auto decides only when the GPU mode is set to software outright. With GPU mode auto, the mode can turn out to be software after the probe has run; such a render stays on BeginFrame, where an unset PRODUCER_FORCE_SCREENSHOT would have switched it to screenshot.
  • A config built with auto carries one new optional field. An older renderer rejects config fields it does not know, so where the config is built on one host and rendered on another, the renderer has to be updated first.

Test plan

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments"

  • packages/engine/src/config.test.ts (130 passed): auto resolves to BeginFrame with the opt-out and the mark; unset, true and false resolve as before and never carry the mark; the run-time software clamp treats auto as an opt-out.

  • packages/producer/src/services/render/stages/probeStage.test.ts (111 passed): auto + software GL + canvas reopens in screenshot mode; auto + no canvas stays BeginFrame; auto + hardware GL stays BeginFrame without looking at the page; without auto the page is never asked; with screenshot already chosen the page is not asked.

  • packages/producer/src/services/distributed/plan.test.ts, with a real browser on Linux: auto + a page with a WebGL canvas records screenshot capture in the plan; auto + a plain page and false + the WebGL page record BeginFrame. With the plan's lock line removed this test fails.

  • tsc --noEmit for engine and producer, oxlint and oxfmt on the changed files.

Not tested here: a full render in auto mode, and the in-process render's follow-through beyond the probe stage's report (it shares the two lines the first-frame fallback uses).

Signed: Rames Jusso

The plan-lock test runs only when the resolved browser is chrome-headless-shell: only that browser has BeginFrame capture, so on any other browser there is no capture mode for a plan to lock and the test skips with a message.

🤖 Generated with Claude Code

jrusso1020 and others added 2 commits November 29, 2026 21:59
auto captures as false does, except that a page holding a WebGL or WebGPU
canvas is captured by screenshot when GL is software. The choice is made
once, after the page opens, and a distributed plan records it for every chunk.
Unset, true and false behave as before.

Signed: Rames Jusso

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed: Rames Jusso

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 275 (base branch 273), smooth 88 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

Quarantined, measured but not gated (0)

…ess-shell

Signed: Rames Jusso

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jrusso1020

Copy link
Copy Markdown
Collaborator Author

Holding this, no review ask for now. Measured on a split render of a 1080p WebGL page (450-frame chunks, software GL): with auto the plan locks screenshot capture as intended and no chunk is redone, but screenshot capture took 58 to 65 ms per frame against 26 ms per frame for BeginFrame on the same page, and the whole render 79.6 s against 58.2 s. In a single-process render the two modes were equal (31.0 against 31.8 ms per frame). So locking screenshot for every page with an accelerated canvas is a net loss wherever BeginFrame works. The 2 s plain clip showed no measurable cost from the extra page check (median 13.8 s, n=9, against 13.9 s). I will come back to this once the cause of the whole-chunk redo is settled.

Signed: Rames Jusso

@jrusso1020

Copy link
Copy Markdown
Collaborator Author

Closing. The whole-chunk recapture this was meant to avoid turned out to come from supersampled renders (the plan recorded BeginFrame for a page that is always captured in screenshot mode), not from accelerated canvases, and locking screenshot for every accelerated canvas made split renders slower. A small fix for the plan follows in its own PR.

Signed: Rames Jusso

@jrusso1020 jrusso1020 closed this Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant