Skip to content

fix(core): Safari keeps a small file's preload and leaves a playing clip's source alone - #7498

Merged
miguel-heygen merged 3 commits into
mainfrom
perf/safari-long-source-release
Nov 10, 2026
Merged

miguel-heygen merged 3 commits into
mainfrom
perf/safari-long-source-release

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

What

Follow-up to #7436. Fixes the two review notes on #7436: on Safari, a small file's clip parsed before the runtime keeps its authored preload, and a clip of a long file that is already playing or seeking keeps its source when its file's size arrives.

Why

  • perf(core): Safari stops a long video's clips from loading the whole file at once #7436's sweep over clips parsed before the runtime set preload="none" on every later clip, before it knew the file's size. A clip of a small file, which the long-file path never touches, then lost the preload its author wrote. On main it keeps it.
  • The file's size arrives asynchronously. A clip a person plays or seeks into before then could be held with no source, or have its src rewritten to #t=<in-point>, which restarts its load and sends a clip on screen back to its in-point.

Two further changes for the head re-read and the late first sound were measured on this branch and taken out, since neither helped in the Simulator measure. They come back only with a measured win.

Size

54 changed lines, standing alone on purpose: these are the review follow-ups to #7436, which has already merged, so no open PR can carry them. Each fix comes with the test that fails without it.

Related work

Refs #7436.

How

  • deferMediaUntilDue's sweep over already-parsed clips still sets a later clip to preload="none", so a long file's later clip is held as before. Once the size check says the file is not long (or the page is outside the player), the clip gets its authored preload back. Clips the observer sees arrive keep preload="none", as on main.
  • When the size arrives, openLongSourceAtInPoint (preloadMedia.ts) leaves a clip that is playing or seeking alone, before both the hold and the in-point open.

Test plan

  • Unit tests added in preloadMedia.test.ts: "leaves the preload of a small file's clip parsed before the runtime as authored", "holds a later clip of a long file parsed before the runtime", "leaves the src of a later clip already playing / seeking when its file's size arrives" (asserts the src is unchanged).
  • fails without the fix: each test fails with its line of the fix removed, checked one at a time on a Linux box: the authored-preload restore for parsed clips (first test), the sweep's preload="none" (second), and the playing check and the seeking check (one case each of the third).
  • preloadMedia, init.longSourceHold, init, mediaProxy and media test files on main plus this change: 596 of 596 pass, 3 runs in a row.
  • The real-Safari audio check caught the first version of the sweep change: it stopped setting preload="none" on a long file's parsed clips too, so they were opened at their in-points instead of held, and the ten-take edit reached 15 to 16 audio seeks against a limit of 15 (9 to 13 on main). The second test covers it.
  • Manual testing: not run, as the change only affects clips that perf(core): Safari stops a long video's clips from loading the whole file at once #7436's measure did not exercise (a small file's preload, a clip played or sought before its file's size arrives).
  • Documentation updated (not applicable)
  • Comments follow CONTRIBUTING.md "Comments"

Base automatically changed from perf/safari-clip-in-point to main November 10, 2026 13:18
@miguel-heygen
miguel-heygen force-pushed the perf/safari-long-source-release branch from df0f146 to 8830f0a Compare November 10, 2026 13:20
@miguel-heygen miguel-heygen changed the title perf(core): Safari lets go of a passed clip of a long file instead of reloading it fix(core): Safari keeps a small file's authored preload and never holds a clip already playing Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 112 of those

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

Quarantined, measured but not gated (8)

Unstable (1)

  • seqplainkeys-none-pct-r0-nested-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@miguel-heygen
miguel-heygen force-pushed the perf/safari-long-source-release branch from 8830f0a to 0c17d91 Compare November 10, 2026 13:30
@miguel-heygen
miguel-heygen marked this pull request as ready for review November 10, 2026 13:31
…sed before the runtime

The sweep sets preload none on them again and gives a clip its authored preload back once its file turns out not to be long.
@miguel-heygen
miguel-heygen force-pushed the perf/safari-long-source-release branch from f21f262 to 0981a75 Compare November 10, 2026 14:11

@heygengenesis heygengenesis Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE · 0 blocker · 1 important (follow-up) · 0 nits · head 0981a755

All three fails without the fix: claims hold. I removed each fix line on its own and ran preloadMedia.test.ts after each removal:

  • Without the notLong restore (passing undefined), only "leaves the preload of a small file's clip parsed before the runtime as authored" fails.
  • Without the sweep's preload="none" (later && !parsedEarly), only "holds a later clip of a long file parsed before the runtime" fails. This is the regression the real-Safari check caught.
  • Without the paused and !seeking checks, only "does not hold a later clip that is already playing when its file's size arrives" fails.

At this head all 42 tests pass, and both CI runs for 0981a755 are green.

Important (not blocking): a playing clip is no longer held, but its source is still swapped mid-play. A clip that fails holdable goes on to openAtInPoint. For a clip that is playing, that call still rewrites src. I changed the playing-clip test to print what it ends with: /m/film-0.mp4#t=30. Setting src starts the load algorithm again, so a clip on screen is paused and sent back to its in-point. That is the fresh read the #7436 nit was about, reached by a different path. It is not a regression: main reaches openAtInPoint for a playing clip with networkState === 2, and it gave a held clip back at #t= on the next tick anyway. Suggested follow-up:

  • In the .then, return before both the hold and openAtInPoint when !el.paused || el.seeking (or el.readyState > 0, as the nit suggested; metadata is already loaded by then, so the in-point open gains nothing).
  • Make the test assert that src is unchanged, rather than only not.toBeNull().
Scope

I read the full preloadMedia.ts at this head. notLong only runs for later clips the sweep parsed early, so clips the observer sees arrive keep preload="none", as on main. A failed size read (bytes === null) and the not-in-player path both restore the authored preload, which matches main for those clips. A long file whose src changed before the size answer stays at none, as before. I did not repeat the Safari audio-seek measurement; the Player Safari audio job is green at this head.

…y playing or seeking

Its file's size can arrive after the clip started; writing an in-point src then restarted its load and sent it back to the in-point.
@miguel-heygen miguel-heygen changed the title fix(core): Safari keeps a small file's authored preload and never holds a clip already playing fix(core): Safari keeps a small file's preload and leaves a playing clip's source alone Nov 10, 2026

@heygengenesis heygengenesis Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE · 0 blocker · 0 important · 0 nits · head e75d831f

The important finding from 0981a755 is fixed. A long file's clip that is playing or seeking now returns before both the hold and openAtInPoint, so its src is never rewritten. The tests now assert that src is unchanged, not just that it is not null. I checked the fails without the fix: claim one check at a time:

  • Without !el.paused, only "leaves the src of a later clip already playing when its file's size arrives" fails.
  • Without el.seeking, only "… already seeking …" fails.

At this head all 43 tests in preloadMedia.test.ts pass. The other three fix tests from my review at 0981a755 are unchanged.

CI: the first CI run at this head failed only in Producer: unit tests, with one test each in renderOrchestrator.videoFrameWindow.test.ts and renderOrchestrator.stall.test.ts (6.8 s and 6.6 s files). This PR does not touch producer code, and the rerun on the same SHA passed. Every other workflow, including Player Safari audio and perf, is green.

Scope

The change since 0981a755 touches only preloadMedia.ts and its test. Moving the paused/seeking check out of holdable and into the early return also skips opened() for a playing clip, so that clip's preload stays none. That has no effect, because the clip is already loading.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit cda8422 Nov 10, 2026
158 of 160 checks passed
@miguel-heygen
miguel-heygen deleted the perf/safari-long-source-release branch November 10, 2026 15:34
@miguel-heygen miguel-heygen mentioned this pull request Nov 10, 2026
3 of 4 tasks
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