Repository navigation
perf(media): start playback sooner and keep Firefox's media worker running - #8
Closed
mickvandijke wants to merge 2 commits into
Closed
mickvandijke wants to merge 2 commits into
mickvandijke wants to merge 2 commits into
Conversation
createMediaSource() opened its reader in the core's streaming mode, which starts fetching ahead, and the file's last record, alongside the first block a player waits for. On the live network that delayed the first frame. Media sources now open an ordinary reader, which still reads ahead once playback's reads follow each other, and keep priming the head and tail. The media service worker installs while the reader opens, and priming starts as soon as the reader is open rather than once the worker controls the page; errors surface in the same order as before. While any media source is open the page messages the worker every 10 s, because Firefox stops a worker that has had no new event for 30 s, even one still answering a request. The worker waits up to 120 s for a block, beyond the core's retries of a missing record after 15 and 45 s, and marks its responses nosniff and sandboxed, since their type comes from the file's metadata. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ten alternating live rounds of createMediaSource() with try's featured video, a real-Firefox check of the worker keep-awake with lowered idle limits, playback through the packaged worker in Chromium, Firefox and WebKit, and the SDK checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 of 7 tasks
Member
Author
|
Folded into #7 so it ships in the 0.1.3 release: this PR's two commits are 🤖 Generated with Claude Code |
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.
Start media playback sooner, and keep Firefox's media service worker running while a source is open. try.autonomi.com streams the same video with the same core, called directly, and started it sooner than
createMediaSource(); this brings what it does differently into the SDK.Stacked on #7, whose 0.1.3 core these measurements use. It targets #7's branch and should be retargeted to
mainonce #7 merges.createMediaSource()opened its reader in the core's streaming mode. That mode starts fetching up to four records of the next 32 MiB, and the file's last record, alongside the first block the player waits for, so they compete for the same connections. Media sources now open an ordinary reader, which still reads ahead once a read continues a previous one, and keep priming the head and tail.X-Content-Type-Options: nosniffandContent-Security-Policy: sandbox; default-src 'none', since their type comes from the file's metadata.Trade-off: seeking to the middle after ten seconds of playback is slower (median 6.5 s against 3.4 s), because streaming mode had by then fetched the window holding it. The change favours a fast start. A core change that serves the first requested range before streaming mode's read-ahead would keep both; that belongs in ant-client and is not part of this PR.
Linear issue
Closes V2-1398
Risk tier
Proposed for human confirmation: no wire, storage or API change. Media playback now asks the network for the records the player reads, with read-ahead once reads follow each other, rather than streaming mode's window from the start.
Compatibility
{ streaming: false }for media readers.createMediaSource()opens a plain reader and installs its worker in parallel with the open; a file of unsupported size (under 3 bytes or beyondNumber.MAX_SAFE_INTEGER) can now leave the worker registered before it is refused. The packaged worker gains amessagelistener, a 120 s block timeout and two response headers. Applications that merged the packaged worker into their own should merge themessagelistener too, as the README now says.Semver impact
Test evidence
Media first-frame audit with the harness, drivers, raw results and logs.
AutonomiClient.connect()on mainnet defaults, thencreateMediaSource()for try's 54.9 MB featured video from its manifest; ten alternating rounds in fresh Chromium 151 contexts, the same harness in both builds. First frame, click to first decoded frame: median 6.6 s against 9.1 s, faster in 7 of 10 pairs. One baseline sample failed (no supported source); every other sample played ten seconds in ten with twowaitingevents. In every sample the first frame is the read of the first record; later blocks came from cache in about 30 ms. Seek to the middle: median 6.5 s against 3.4 s, as above.206with an empty body after 15 s, the worker stopped mid-answer. This branch: the requested bytes after 22 s, two keep-awake messages while open and none after closing.npm run check: build, TypeScript and 262 tests in 23 files passed. New tests cover the parallel worker setup and priming with a plain reader, a failed worker surfacing after the open and closing the reader, the bridge doing nothing more once its worker controls the page, keep-awake only while a source is open, and the worker's listener, timeout and headers; five of them fail against feat: add large-file streaming, recoverable pointers and manifest exports #7's source, and the ordering test guards the new parallel setup. All five example builds,npm pack --dry-run(97 files),npm run verify:wasm, ADR governance (8 ADRs) and all 52 PR-checker cases passed.Live timings vary with the network: one machine, Chromium only, one video, unknown node load.
New dependency
none
ADR
n/a for Tier 1. The decision is recorded as a dated amendment to Proposed ADR-0003.
Mitigation / rollback
Revert this PR to restore streaming-mode media readers; deploy the packaged worker with the SDK, as for any SDK release.
🤖 Generated with Claude Code