Skip to content

VOD cold-start pays a mandatory sequential head→tail→re-anchor round trip on non-fast-start MP4 sources — request for parallel fetch or moov-offset hint #281

Open

Description

@digilearn-dev

What happened?

On every fresh VOD load against a non-fast-start MP4 source (moov atom at file end), the demuxer open sequence costs 1.2-2.8s of pure network round-trip time before frame rate / stream metadata is available, via three sequential connections:

gen=1: offset=0, len=32MB → real data connection (~1-2s)
gen=2: offset=, len=0MB → moov atom / tail probe (~130-750ms)
gen=3: offset=, len=32MB → re-anchor (~45-100ms)

This is confirmed consistent across multiple sessions and titles on our end. It's occurring before any codec/DisplayCriteria logic engages, so it's purely the cost of locating and reading the trailing moov atom.

I checked #69 and see this matches the documented non-fast-start MP4 behavior — the detour-block cache fix there collapsed what could otherwise be a reconnect storm down to this legitimate minimum sequence, but the sequential round-trip cost itself remains by design. I'm not reporting a regression from that fix; I'm asking whether there's room to reduce this legitimate minimum further, since for slower/higher-latency sources (debrid-style proxies in our case) this is now the single largest contributor to VOD time-to-first-frame — bigger than anything in the DisplayCriteria path (#274/#277).

Steps to reproduce

  1. Load a VOD title from a non-fast-start remote MP4 source (moov atom at end of file) with meaningful network latency to the host (not a fast local/CDN path).
  2. Observe AVIOReader logs: pump conn start gen=1 offset=0, followed by pump conn start gen=2 offset= len=0MB, followed by pump conn start gen=3 offset=<near 0>.
  3. Measure elapsed time from open_started to the point frame rate/stream info becomes available — the three round trips dominate this window on higher-latency sources.

AetherEngine version or commit SHA

6.4.3

Host app

Custom / my own integration

Platform

tvOS

OS version

tvOS 26.6 (beta)

Device / chip

Apple TV 4K (A15)

Playback path

Native AVPlayer

Source media (for playback bugs)

Various VOD titles served via a remote HTTP source (debrid-style proxy) producing non-fast-start MP4 (moov atom at file end). Not codec/resolution-specific.

Error codes / log lines

[AVIOReader] pump conn start gen=1 offset=0 len=32MB
[AVIOReader] File size: 4502623452 bytes (data connection)
[AVIOReader] pump gen=1 first data after 1011ms
[AVIOReader] pump conn start gen=2 offset=4502622327 len=0MB
[AVIOReader] pump conn gen=1 ended with error: cancelled
[AVIOReader] pump gen=2 first data after 747ms
[AVIOReader] pump conn start gen=3 offset=5756 len=32MB
[AVIOReader] pump gen=3 first data after 103ms

No errors — this is expected, working behavior, just a real latency cost we're asking about.

Anything else

Checked the public LoadOptions surface (6.4.3) exhaustively before filing — confirmed there's no host-facing content-length hint, moov-offset hint, parallel head+tail fetch option, or way to influence this open sequence. probesize/maxAnalyzeDuration (#68) only bound find_stream_info after the demuxer is open; they don't affect the need to seek to a trailing moov. Also checked #70 (redundant size probe removal) and #126 (moov-at-end + unknown length) as related prior work — this report is a step beyond both, not a regression of either.

Possible directions, offered as starting points rather than a specific implementation ask:

Issue the tail probe (gen=2) concurrently with the initial data connection (gen=1) rather than sequentially, since they're logically independent reads.
A host-supplied content-length or last-known-moov-offset hint (keyed by URL) for sources the host already has size/duration metadata for via other means (e.g., from a provider API), letting the engine skip straight to the real read.
A durable moov-offset cache keyed by URL for repeat plays of the same file, if the in-process SourceContentLengthCache (#112) could be extended or paralleled for this purpose — understanding that's currently internal/enum-based and not something we're asking to be made public, just flagging it as prior art that might already be close to reusable internally.

Not a regression, not blocking — flagging as an opportunity, since this is now the largest single contributor to VOD cold-start time on our slower sources, larger than anything in the DisplayCriteria path.

Activity

  1. added
    bug
    on Aug 2, 2026
  2. added a commit that references this issue on Aug 2, 2026
  3. superuser404notfound commented on Aug 2, 2026

    @superuser404notfound
    Owner

    Released as 6.4.5 (a2087a5, fix in 69b6e031). Thanks for the trace with the three generations and their first-data times, that is what made this diagnosable without access to the source.

    One of the three round trips was ours, and it is gone. The report reads gen=2 and gen=3 as two costs of the layout. Only gen=2 is. seekReconnect resets the reader's window, so the seek to the trailing object discarded bytes that had been resident moments earlier, and gen=3 went back to re-fetch them. The window is now parked across a parse seek and serves that return as a copy, released once the demuxer's header pass is done (after which a far seek is a scrub, where the old window is worthless). That half costs no additional bytes anywhere.

    gen=2 now overlaps gen=1 rather than queueing behind it. open() issues one speculative 64 KB suffix range. bytes=-n needs no size, which is the reason it can go out before the first response header exists, so it does not have to wait for the size resolution your gen=1 provides. It covers the small trailing objects an open reads: mfra on fragmented MP4, and a trailing moov whose sample tables fit.

    Measured here against a Range-logging origin on a 51 MB moov-at-end file: three sequential requests become two concurrent ones, with the tail read and the return trip both absent.

    Where it will not help, stated plainly. A moov grows with the sample count, so a feature-length file's runs into megabytes and will not fit in 64 KB. That request stays. Sizing the speculative fetch to cover it was considered and rejected: it would spend real bandwidth on a guess, competing with the first data connection on exactly the slow links this is meant to help. The parked window still removes the return trip in that case, so the worst case goes from three round trips to two rather than to one.

    On your source specifically the tail sits about 1125 bytes from EOF, which fits the suffix window with room to spare, so both halves should apply. If the numbers say otherwise, the thing to capture is whether a bytes=-65536 request appears alongside the first one.

    On the other two directions in the report. The durable per-URL moov-offset cache is a reasonable idea but a later one: it only pays on a repeat play of the same file, while this pays on every cold start, and the two do not conflict. The host-supplied moov-offset / content-length hint I would rather not add. The offset is not something a host generally knows (a provider API gives size and duration, not box layout), so the surface would be correct only for hosts that parse the container themselves, and a wrong hint costs a wasted fetch plus the round trip it was meant to replace.

    Leaving this open until your retest.

  4. digilearn-dev commented on Aug 2, 2026

    @digilearn-dev
    Author

    Retested on 6.4.5 across several fresh cold VOD plays (MP4 sources, same file type as the original report). bytes=-65536 doesn't appear in any session — the connection pattern is unchanged from before the fix: fully sequential gen=1 → gen=2 (tail probe) → gen=3 (re-fetch of start), sometimes a 4th hop. This holds even on a fast-network session (gen=1 first data in 126ms), where the shape should be most visible if the fix were engaging — ruling out network variance as the explanation.

    Three sessions, same show/source, different episodes:

    Session A — ttff_ms=3577

    [AVIOReader] pump conn start gen=1 offset=0 len=32MB
    [AVIOReader] File size: 3399970254 bytes (data connection)
    [AVIOReader] pump gen=1 first data after 1720ms
    [AVIOReader] pump conn start gen=2 offset=3399969134 len=0MB
    [AVIOReader] pump conn gen=1 ended with error: cancelled
    [AVIOReader] pump gen=2 first data after 438ms
    [AVIOReader] pump conn start gen=3 offset=265159 len=32MB
    [AVIOReader] pump gen=3 first data after 66ms
    [AVIOReader] pump conn start gen=4 offset=3399889966 len=0MB
    [AVIOReader] pump conn gen=3 ended with error: cancelled
    [AVIOReader] pump gen=4 first data after 121ms

    Session B — ttff_ms=3428

    [AVIOReader] pump conn start gen=1 offset=0 len=32MB
    [AVIOReader] File size: 3652742915 bytes (data connection)
    [AVIOReader] pump gen=1 first data after 1892ms
    [AVIOReader] pump conn start gen=2 offset=3652741792 len=0MB
    [AVIOReader] pump conn gen=1 ended with error: cancelled
    [AVIOReader] pump gen=2 first data after 351ms
    [AVIOReader] pump conn start gen=3 offset=262318 len=32MB
    [AVIOReader] pump gen=3 first data after 66ms
    [AVIOReader] pump conn start gen=4 offset=3652654288 len=0MB
    [AVIOReader] pump conn gen=3 ended with error: cancelled
    [AVIOReader] pump gen=4 first data after 91ms

    Session C (fast network — shows the shape is unchanged even when latency isn't the bottleneck) — ttff_ms=614

    [AVIOReader] pump conn start gen=1 offset=0 len=32MB
    [AVIOReader] File size: 4502623452 bytes (data connection)
    [AVIOReader] pump gen=1 first data after 126ms
    [AVIOReader] pump conn start gen=2 offset=4502622327 len=0MB
    [AVIOReader] pump conn gen=1 ended with error: cancelled
    [AVIOReader] pump gen=2 first data after 56ms
    [AVIOReader] pump conn start gen=3 offset=4502516117 len=0MB
    [AVIOReader] pump gen=3 first data after 39ms
    [AVIOReader] pump conn start gen=4 offset=5752 len=32MB
    [AVIOReader] pump gen=4 first data after 39ms

    Confirmed AetherEngine is pinned to 6.4.5 (Package.resolved), and the checkout does contain the tailPrefetchBytes/startTailPrefetch() code per our build. But at runtime, none of these sessions show the speculative suffix request firing, concurrently or otherwise. Happy to test any specific config or angle if there's something on our end worth checking first.

  5. superuser404notfound commented on Aug 2, 2026

    @superuser404notfound
    Owner

    The retest is right, and the reason is worse than a partial fix: the speculative fetch could never have won its race. Released as 6.5.1 (edb0946, fix in 2530a33c).

    Nothing on that end was worth checking. The three traces are exactly what 6.4.5 predicts once the timing is measured instead of assumed. The demuxer reaches the trailing object within microseconds of the data connection's first byte. The suffix fetch pays the same round trip plus a body, so on any origin whose first byte costs anything it is still on the wire at exactly the moment the read arrives, and since nothing waited on it, the reconnect happened anyway. It never once served the read it exists for. It only added a request.

    Only a loopback origin, which answers before that race can be lost, made it look like it worked: six tests passed while the field trace stayed flat. The regression test now models an origin whose first byte costs something, and it fails against 6.4.5 with the same three-request shape reported here.

    A read landing in the fetched range now waits for it. The bound is what a round trip against the origin was measured to cost, taken from the data connection's own time to first data, since both requests left at the same instant: past that the fetch is not about to land and a fresh connection is the better bet. Waiting up to that point can never cost more than the reconnect it replaces. An origin that declines suffix ranges reports a terminal outcome now, so the waiter wakes on the rejection rather than sitting out its budget.

    The bytes=-65536 check was not a fair thing to ask for. The engine never printed that request, so its absence from a log was not evidence of anything, and this thread has now spent a round on that twice. 6.5.1 prints it:

    [AVIOReader] pump tail prefetch issued bytes=-65536
    [AVIOReader] pump tail prefetch installed 65536B at <offset> after <n>ms
    [AVIOReader] pump tail prefetch served the read at <offset>; no reconnect for it
    [AVIOReader] pump parked window served the return to <offset>; no reconnect for it
    

    A declined fetch says how it was declined (status=416 (no suffix range support), a Content-Range that does not describe the 65536 B asked for, a short body). Slow reads gained tailWaits=.

    What the traces say about these sources, since they are more informative than the original report. Two trailing objects are read per open, not one:

    first tail read second tail read
    A EOF-1120 EOF-80288
    B EOF-1123 EOF-88627
    C EOF-1125 EOF-107335

    Only the first fits a 64 KB suffix window. The second keeps its own request on every one of these files, and that is deliberate: a moov grows with the sample count, so sizing the speculative fetch to cover 107 KB here would mean spending real bandwidth on a guess, on exactly the slow links this exists to help. So the expectation for the next trace is four connections becoming two, not one: the data connection, and the deeper trailing object. gen=2 should be gone outright. The return to the head (offset 5752 in session C, 265159 in session A) is served from the parked window when the data connection had delivered that far by the time of the parse seek, which is near certain at 5752 and a coin flip at 265159 given that gen=1's first byte landed 1720 ms in.

    Thanks for retesting on three separate sources and for including the fast-network session. That last one is what ruled out the obvious explanation and pointed at the shape rather than the link. Leaving this open until the next retest.

  6. superuser404notfound commented on Aug 2, 2026

    @superuser404notfound
    Owner

    Follow-up, and it goes further than the fix in 6.5.1. Released as 6.5.2 (7691cef).

    After 6.5.1 I took the remaining hop in these traces to aetherctl, the engine's CLI harness, against a Range-logging origin with real per-request latency, across six container layouts. It found three more defects, all the same shape as the one this issue started with: bytes already in hand were thrown away and fetched again.

    • A range that finished delivering was fetched again. A completed range clears the active task exactly as a dropped one does, and the branch that reconnects when there is no connection ran at the read position regardless, dropping everything still resident. A parse pass is exactly the consumer that hurts: it reads one 256 KB AVIO buffer at a time while the transfer runs at line rate. A 764450 B trailing moov cost three connections and 1506918 delivered bytes, 1.97x its own size.
    • A read at the end of the file opened a connection for it. The EOF decision sat below that reconnect, so bytes=<fileSize>- went out first and the empty 206 it came back with reset the window past the last byte.
    • The parked window from 6.4.5 was cut from the wrong place. It cut from the reader's window start, on the reasoning that the demuxer returns there. It returns to the head of the FILE: landings of 48, 1161, 5752 in the fixtures and 265159 in the trace above. Those coincide only when the parse seeks away before reading anything. A fragmented MP4 reads 33 MB first, so the parked copy began megabytes past everything the return asked for and served nothing on any layout measured. The head is now retained as it arrives instead, and the park is gone.

    What these sources are, as far as the matrix can say

    layout requests per open what served the tail
    faststart MP4 2 nothing
    moov at end, 23337 B 2 the suffix fetch
    moov at end, 764450 B 3 retained head; the moov is too big for the suffix
    fragmented, mfra at end 3 suffix fetch (mfra) + retained head
    MKV, Cues at end 2 nothing
    MKV, Cues at front 2 nothing

    The traces here match the fragmented row: a small trailing object about 1120 B from the end, which the suffix fetch covers, and a deeper read that does not.

    That deeper read is a media fragment, not an index. In the fixture it sits at EOF-4739057; here at EOF-80288, EOF-88627 and EOF-107335. Its distance from the end scales with the fragment size, so there is no suffix window that covers the class, and sizing the speculative fetch toward it would spend real bandwidth on a guess. It keeps its own request, deliberately.

    For the same reason the suffix fetch stays at 64 KB rather than growing, and there is now a number behind that: five runs per point at 250 KB/s with 300 ms of latency, it costs 252 ms on a layout that does not use it, exactly the link time of 64 KB, and saves 360 ms on one that does. Those are equal at about 2 Mbit/s, which cannot stream this material anyway.

    What to expect on a retest: two connections rather than four, pump tail prefetch served the read at <offset> for the object near the end, and pump retained file head served the return to <offset> for the trip back. The wall-clock share is modest, since the first byte of the data connection is 1720 ms and 1892 ms of a 3577 ms and 3428 ms open in two of these three sessions, and nothing on this side can overlap that first round trip.

    Leaving this open until then.

  7. digilearn-dev commented on Aug 3, 2026

    @digilearn-dev
    Author

    Retested on 6.5.2 across four fresh cold-start sessions on our source. Mixed result, but for a reason your fix already anticipates — worth reporting precisely rather than as a pass/fail.

    The origin doesn't support suffix range requests at all. Every single session shows the tail prefetch getting rejected:

    pump tail prefetch rejected after 699ms: status=200 (no suffix range support)
    pump tail prefetch rejected after 4643ms: transport: The request timed out.
    pump tail prefetch rejected after 3378ms: status=200 (no suffix range support)
    pump tail prefetch rejected after 292ms: status=200 (no suffix range support)

    It either ignores the Range header and returns a full 200 instead of 206, or times out. So the near-EOF tail-object optimization never gets to engage on this source, structurally, regardless of the client-side implementation. The fast-fail-on-rejection behavior is working correctly though — every rejection resolves in well under a second in three of four cases, rather than sitting out the full wait budget.

    The retained-file-head half is working, consistently, in every session:

    pump retained file head served the return to 5756/5593/5593/5613; no reconnect for it

    That's a real, confirmed win independent of the suffix-range issue — one hop removed every time.

    Net result on this origin: still 5–8 connections per session rather than the 2 we were hoping to see, since with suffix ranges rejected outright, the deep media-fragment reads each still need their own connection — but that's one fewer than before this whole optimization existed, thanks to the retained-head piece landing cleanly.

    ttff_ms this round was rougher than earlier sessions (5.8–9.1s), but that looks like genuinely poor network conditions during this test batch rather than anything related to the fix — one session's data connection alone took 4.8s for first byte.

    Full traces for one representative session, in case useful:

    [AVIOReader] pump tail prefetch issued bytes=-65536
    [AVIOReader] pump conn start gen=1 offset=0 len=32MB
    [AVIOReader] pump gen=1 first data after 695ms
    [AVIOReader] pump tail prefetch rejected after 699ms: status=200 (no suffix range support)
    [AVIOReader] pump conn start gen=2 offset=4502622327 len=0MB
    [AVIOReader] pump gen=2 first data after 179ms
    [AVIOReader] pump retained file head served the return to 5756; no reconnect for it
    [AVIOReader] pump conn start gen=3 offset=4502516117 len=0MB
    [AVIOReader] pump gen=3 first data after 40ms
    [AVIOReader] pump conn start gen=4 offset=3162677 len=32MB
    [AVIOReader] pump gen=4 first data after 165ms
    [AVIOReader] pump conn start gen=5 offset=5752 len=32MB
    [AVIOReader] pump gen=5 first data after 865ms
    [AVIOReader] pump conn start gen=6 offset=33560184 len=32MB
    [AVIOReader] pump gen=6 first data after 47ms
    [AVIOReader] pump conn start gen=7 offset=67114616 len=32MB
    [AVIOReader] pump gen=7 first data after 44ms

    Happy to test against any other source type if that would help narrow down which origins genuinely support suffix ranges versus which don't — this feels like it might just be a property of this particular provider's server rather than something further tuning on the client side could address.

  8. superuser404notfound commented on Aug 3, 2026

    @superuser404notfound
    Owner

    Both halves of that retest were worth reporting the way you reported them, and the trace carried a second defect that the report did not claim. Released as 6.5.5 (f4a907b, fix in 979ad8d0).

    The suffix-range half is your origin, and the client can only stop paying for it. A server that answers bytes=-65536 with a 200 cannot be talked into the optimisation from this side, and re-issuing the request per open was not free even though the body was refused at the header: it is a second connection opened at the same instant as the data connection whose first byte is the entire cold start, sharing the same uplink, against a server that has already given its answer. That answer is now remembered per origin (scheme, host, port) for the session. The first open of a session still asks once, then the log says tail prefetch skipped: this origin declined suffix ranges earlier this session (status=200 (no suffix range support)). Only the origin's own answer latches on the first occurrence; a timeout takes two, since a link bad enough to lose that request loses others, and one of your four sessions timed out where the other three were answered.

    The finding your trace carried, and it is ours, not the origin's. These two lines:

    [AVIOReader] pump conn start gen=4 offset=3162677 len=32MB
    [AVIOReader] pump conn start gen=5 offset=5752 len=32MB
    [AVIOReader] pump gen=5 first data after 865ms
    

    gen=4 is the parse running off the end of the retained head, which stops where the data connection was cancelled. gen=5 is playback's first read, and 5752 is inside the head that had just served the return to 5756 four lines earlier. It reconnected because the head was released the moment the demuxer finished parsing, on the reasoning that a far seek from there on is a scrub whose landing zone the head cannot serve. That is true of a scrub and wrong about the read that actually comes next: after a trailing-index parse the anchored connection sits at the END of the file, so playback's first read is a backward one, and on every layout measured it lands at the head. Your 865 ms is what that costs on a real link.

    Why the previous round could not see it. The whole six-layout matrix behind 6.5.2 was measured with aetherctl probe, and probe exits at exactly the call that released the head. The measurement said the layouts were settled because it stopped one read before the defect. Redone with play against an origin carrying 300 ms per request, on a fragmented fixture:

    playback's first read already-resident bytes re-fetched
    6.5.4 new connection at 263303 3.93 MB
    6.5.5 served from the retained head, next connection deferred to 4194304 none

    The head is now released by the first post-open read it cannot answer instead, so a resume position far into the file drops it immediately and playback from the start keeps it exactly as long as it is being read.

    What to expect on your source. gen=5 should be gone, replaced by retained file head served playback's first read at 5752; no reconnect for it, which is deliberately a different line from the served the return to one 6.5.2 already printed for the parse. That is one connection fewer and it is the one sitting on the first frame.

    On the 5 to 8 connections. That count is not all cold start, and it is worth separating. In the session you posted, gen=6 at 33560184 and gen=7 at 67114616 are 5752 plus exactly 32 MiB and 64 MiB: that is the bounded streaming window advancing during playback, requested at the frontier before the window drains, which is deliberate and costs nothing on the critical path. What the cold start itself costs on this source after 6.5.5 is the data connection, the small trailing object, the deep media fragment, and the reconnect where the head runs out. The deep read keeps its own request on purpose, because it is a media fragment rather than an index and its distance from the end scales with the fragment size, so no suffix window covers that class.

    And the honest limit: with a data connection whose first byte took 4.8 s in one of those sessions, nothing on this side overlaps that first round trip. The ttff range you saw is dominated by it.

    Thanks for reporting the rejection lines verbatim rather than as a pass or fail. The per-open cost of a request that cannot be answered was only visible because the reason was in the log four times, and the gen=4 and gen=5 pair is what made the head lifetime measurable at all. Leaving this open until the next retest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions