Skip to content

fix(viewer): drive the frame loop with a timer when ?disable=draw#483

Merged
wass08 merged 1 commit into
mainfrom
fix/bake-timer-frameloop
Jul 10, 2026
Merged

fix(viewer): drive the frame loop with a timer when ?disable=draw#483
wass08 merged 1 commit into
mainfrom
fix/bake-timer-frameloop

Conversation

@wass08

@wass08 wass08 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Follow-up to #482. On Linux (the headless bake worker), Chromium's no-damage scheduler throttles requestAnimationFrame to 1Hz when the page never submits a real frame — measured in the prod-image container: main thread fully idle, rAF gaps exactly 1017ms, so every useFrame system ticked once per second and a heavy scene needed 300+ seconds just to execute its ~300 frames of build work (and blew the capture deadline on the worker's slower cores). The #482 empty-scene clear prevents this on macOS but not on Linux.

Fix: when ?disable=draw is active, FrameLimiter drives advance() from setInterval instead of rAF. Foreground-page timers are never throttled, so loop pacing is deterministic (the fps prop) regardless of compositor heuristics. The normal rendering path is unchanged (still rAF).

How to test

  1. bun dev, open /bake/demo_office?disable=postFx,drawwindow.__BAKE__ resolves in seconds (validated: 8.9s for a 200+-item scene, output in the normal byte range).
  2. Any page without draw — unchanged (verified demo_1 normal render byte-equal).
  3. Real proof is the prod worker post-merge: the office scene (project_2VqMH2p0YduKVd3i) should complete a headless CPU-only bake for the first time.

Screenshots / screen recording

N/A — headless-only behavior.

Checklist

  • I've tested this locally with bun dev
  • My code follows the existing code style (run bun check to verify)
  • I've updated relevant documentation (if applicable)
  • This PR targets the main branch

🤖 Generated with Claude Code


Note

Low Risk
Scoped to the ?disable=draw code path; normal viewer rendering still uses rAF unchanged.

Overview
When ?disable=draw is set (headless bakes that skip real drawing), FrameLimiter now advances the R3F loop with setInterval at the configured fps instead of requestAnimationFrame.

On Linux, Chromium throttles rAF to ~1Hz when no real frames are submitted, which made useFrame systems crawl during bakes. Timers stay at full rate on a visible page, so build work can finish in seconds without changing the normal rAF path when drawing is enabled.

Cleanup cancels the interval on unmount alongside the existing rAF teardown.

Reviewed by Cursor Bugbot for commit 892eb62. Bugbot is set up for automated code reviews on this repo. Configure here.

With no real frames submitted, Chromium's no-damage scheduler throttles
requestAnimationFrame to 1Hz on Linux — measured in the headless bake
worker: every useFrame system ticked once per second, so a heavy scene
needed 300+ seconds of wall time just to run ~300 frames of build work
(and exceeded the capture deadline on the worker's slower cores). The
empty-scene clear from #482 avoids this on macOS but not on Linux.

When `draw` is disabled, drive advance() with setInterval instead of
rAF — plain timers are never throttled on a visible page, so the loop
pacing is deterministic (fps prop) regardless of compositor heuristics.
Normal rendering paths are untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wass08 wass08 merged commit aa30899 into main Jul 10, 2026
2 checks passed
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