Repository navigation
perf(core): open the preview's audio context when a clip with sound plays - #7658
Conversation
Edit accuracy: accurate 267 (base branch 267), smooth 92 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
There was a problem hiding this comment.
Approving at c8198641.
The "fails without the fix" line checks out. I ran packages/core/src/runtime/init.webAudioLazy.test.ts with init.ts and webAudioTransport.ts reverted to the parent commit. "builds none while a page with sound only loads" and "builds none when a page with no sound plays" both fail with expected 1 to be +0. At this head, that file and init.swapScenes.test.ts pass (173/173).
Correctness:
open()is idempotent (if (this._ctx) return true), andwebAudioOpened ??=remembers a failed open, so no-Web-Audio browsers aren't retried on every play.- Every call into the transport before the context opens takes the path the old code already took when
init()failed or hadn't resolved yet. That coverssetVolume/setMuted/setGroupMuted, metering,ownsClock/contextin the clock source, and decode with_ctxnull. Volume, mute and metering are applied at open (applyMasterGain,attachMasterTap), so no state is lost. - The three scheduling entry points (play, a scene joining a playing film, rate change) are gated correctly. The rate-change path uses
webAudioOpened === truerather than callingopenWebAudio(). The PR description says it opens there, but checking state is the right behaviour: if nothing was opened, nothing is scheduled to reschedule. - Autoplay: before this PR the context was also created outside a user gesture, at load, so creating it at play doesn't change behaviour.
CI is green on this head: CI, Windows render verification, regression, preview-regression, Player perf, Safari perf, Safari audio, and CodeQL.
Non-blocking:
- As the PR says, the device-open cost now moves to the first play of a page with sound, and nobody has measured it on a real Windows device. Worth checking the first Windows stall reports after this ships (PRINFRA-6303).
- If the page had no sound when it started playing, audio added later only routes through Web Audio after the next play or a scene join. This is an edge case, and native playback covers it in the meantime.
…gen-com#7658, ccdcf67) Adopts upstream heygen-com#7658: a paused preview or a silent composition no longer opens the Web Audio context. Adds regression tests for early opening and a CLI docs note. Implemented by Codex (gpt-6.2-sol); committed by the reviewer because the Codex sandbox cannot write the worktree index. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Records the remaining batch 6 decisions: heygen-com#7658 adopted (7164b5a), heygen-com#7684 adopted, heygen-com#7659 and heygen-com#7679 deferred with revisit conditions, and the heygen-com#7655/heygen-com#7664 summary. Updates REVIEW.md notes and ROADMAP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…en-com#7658, heygen-com#7673) - core: create the preview AudioContext before starting the playback clock, so a slow context start no longer drops the opening audio (heygen-com#7658). - cli: `check --samples` accepts 1-10,000; larger values are usage errors instead of a RangeError (heygen-com#7673; upstream also accepts 1e10). - docs: preview audio startup, sample limit, REVIEW SHA for heygen-com#7684. Upstream: ccdcf67, 564a597, 92816ed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
The preview runtime opens its audio context when a clip with sound first plays, not each time a page loads. A page with no sound never opens one.
Why
Opening an
AudioContextopens the audio device on the page's own thread. On Windows that can take seconds, and every preview load paid it, so a window that reloaded its preview while files changed froze again and again with nothing playing. The runtime built the context ininit()for every page, sound or not.Related work
Refs the Windows preview freezes; no open issue here.
How
WebAudioTransport.open()builds the context synchronously and returns whether it worked;init()now calls it. Ininit.tsplay and a scene joining a playing film callopenWebAudio()first, and only when the page has clips with sound; a rate change only reschedules if the context was already opened. A failed open is remembered, so a browser with no Web Audio is not retried on every play. Opening at play also means the first play already has its context, where the old load-time open was ready only a microtask later.What I measured
init.webAudioLazy.test.ts: 3 of 3. A page with sound that only loads builds 0 contexts; a page with no sound that plays builds 0; a page with sound builds exactly 1 however often it plays.src/runtimewhole directory on a Linux box: 138 files, 3,181 tests, all pass (one mock ininit.swapScenes.test.tsnow stubsopeninstead ofinit).packages/core/src/runtime/init.webAudioLazy.test.ts"builds none while a page with sound only loads" fails on main withexpected 1 to be +0, and "builds none when a page with no sound plays" fails the same way.What I did NOT exercise
AudioContext, so how many seconds the first play now waits on a slow device is unmeasured. The wait moves to the first play of a page with sound; it is not removed.Test plan