Skip to content

fastZap on an engine-cut raw MPEG-TS source: about 1 s of every bounded start on an Apple TV is the second request's grace (#594's open question), and an offer to run the A/B #686

Closed

Description

@cmcpherson274

Device data on the question 9a1d9e6d left open, with an offer. Not a correctness defect.

Setup. Apple TV 4K (3rd generation, AppleTV14,1, tvOS 26.6), Debug builds of our app (the engine at -Onone), three test sessions on 2026-10-01. A live 1080p59.94 H.264 + AAC channel delivered as raw MPEG-TS; our app spools it and hands the engine a custom IOReader over that spool, isLive, .fastZap, liveJoinStartsImmediately = true. 7.24.0 (9bd00968) and 7.17.1 (7d2d1f21), one run per leg.

The reading. On an engine-cut source every plain GET /media.m3u8 re-enters the first-serve gate (HLSLocalServer.swift:1041-1058 at 7.24.0). When the first manifest went out as a fastZap bounded start (cushion below the holdback), AVPlayer's second plain request arms a fresh grace (VideoSegmentProvider.swift:2400-2434, length :382-386) and is answered when that grace ends, unless the cushion fills first. That exit logs nothing (the account latch at :2497).

first serve n second plain request held init.mp4 requested after the first manifest first media segment requested
bounded start (cushion < holdback) 13 (8 at 7.24.0, 5 at 7.17.1) 1.015 to 1.384 s 1.035 to 1.403 s 1.045 to 1.413 s
full cushion 14 (8 on this channel, 6 on a second raw-TS test source) 2 to 6 ms

That is every first serve in those three sessions. The hold is the same on both versions (7.17.1: 1.017 to 1.022 s). All 12 cold tunes of this channel in those logs were bounded starts (2 to 3 segments at the first manifest), so about 1 s of each cold start is this hold: in one tune whose started line reads 5.8 s, 1.30 s was the second request waiting.

What this is and is not. These readings are all WITH the grace. 9a1d9e6d kept #684's first-serve latch for ingest sessions only and says of engine-cut raw TS under fastZap that without the second grace the first picture comes about 2 s sooner and the session sits closer to the producing edge for its whole life, "which nobody has measured on a device", calling it #594's open question. We have not measured that either: it needs the arm.

The offer. If you add an env-gated arm that applies the latch to engine-cut sources (as AETHER_BOUNDED_START_FLOOR did for #594), we will run it both ways on this Apple TV, interleaved, on cold tunes and on rebuilds from a 6 s backlog, and post start time, stats final stalls, -16832, -12888 and distance behind live after 60 s. Redacted slices on request.

Activity

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

    @superuser404notfound
    Owner

    Thanks for the numbers and for the offer, taken up. The arm is in 7.26.3 (7ac28fa4), via PR #692.

    Arm. AETHER_FIRST_SERVE_LATCH_ALL=1 in the process environment applies the #684 first-serve latch to engine-cut sources as well, so on raw MPEG-TS the second plain GET /media.m3u8 passes at once after the first manifest went out. It is read once per process, so set it in the scheme (or launch environment) before the engine is first touched; without it 7.26.3 behaves exactly like 7.26.2.

    New line, both arms. The silent exit you pointed at now reports, once per session:

    [HLSVideoEngine] repeat live manifest request held 1.011s, fastZap bounded start after 1.000s grace   (arm off)
    [HLSVideoEngine] repeat live manifest request held 0.000s, first-serve latch                          (arm on)
    

    On a full-cushion first serve the arm-off line reads a few ms with no note, as in your second table row.

    Mac reference. aetherctl live --fast-zap --realtime --preroll 0 --seconds 40, two runs per arm, interleaved, on a 1080p59.94 H.264 + AAC seed with 1 s GOPs (first serve: 3 segments, bounded):

    arm second request held GET /init.mp4 sustained clock advance playhead after 40 s
    off 1.011 s 2.43 s 3.2 s 38.30 to 38.40 s
    on 0.000 s 1.41 to 1.44 s 1.1 s 39.19 to 39.30 s

    So the arm removes exactly the grace, and the session ends that much closer to the edge. No stall in either arm, but that half is precisely what this harness cannot price: the fixture session joins at the head of the served window and never seeks to edge-minus-holdback (see the #594 section of docs/cli.md). That is what your Apple TV runs answer.

    The metrics you listed (start time, stats final stalls, -16832, -12888, distance behind live after 60 s) are the right ones; the rebuild-from-a-6 s-backlog case is the one I am least sure about, since there the second grace may have been buying cushion the shallow window lacks. Whether the latch becomes the default for engine-cut sources gets decided on those results.

  3. cmcpherson274 commented on Oct 6, 2026

    @cmcpherson274
    Author

    Here is the A/B from your comment above, on the Apple TV, in the metrics you listed: 7.27.3 with and without AETHER_FIRST_SERVE_LATCH_ALL=1.

    Setup. Apple TV 4K (3rd generation, AppleTV14,1, tvOS 26.6), Debug builds of our app (the engine at -Onone), four test sessions on the morning of 2026-10-06. Live 1080p59.94 H.264 + AAC channels delivered as raw MPEG-TS; our app spools each one and hands the engine a custom IOReader over that spool, isLive, .fastZap, liveJoinStartsImmediately = true, as in the opening post. One build of 7.27.3 (b27f2971; VideoSegmentProvider.swift is the same blob as at 7.26.3). Every run is a fresh app launch: ON sets the variable in that launch's process environment and OFF does not, alternating OFF, ON, ON, OFF, OFF, ON within a session. Every ON launch logs first-serve latch on its repeat-request line and no OFF launch does. The scene-cut key frames upstream of us are now off (our comment on #670): on both channels every first serve here sealed TARGETDURATION 2 with 1.001 s segments, so the holdback is 6 s throughout.

    Columns. Start is the engine's own #361 startup 0/8 dispatched → 8/8 presenting. Held is your new line. Behind live is how far the picture is behind the newest data our app has received from the server, about 60 s after the tune locked (or after the rebuild). Our index of that data moves in 1 s steps, so one reading carries up to 1 s of sawtooth; on every run below the median of the samples from +30 to +80 s is within 0.34 s of the +60 s one. Stalls is stats final, summed over a run's playback sessions (a zap run has two, one per channel). Three runs per arm unless marked; median [min–max].

    Tunes whose first serve is bounded (2 or 3 segments, under the 6 s holdback):

    tune arm first serve (segments) held (s) first serve → presenting (s) start (s) stalls -16832 -12888 behind live at +60 s (s)
    cold tune OFF 2, 2, 3 1.003–1.006 1.068–1.082 4.363 [3.810–4.945] 1 † 0 4 † 5.21, 5.61 †
    ON 3, 2, 2 0.000 0.061–0.065 3.313 [3.121–3.728] 0 0 0 4.11 [4.01–4.41]
    zap to a second channel (that channel's tune) OFF 3, 2, 3 1.002–1.006 1.067–1.073 3.815 [3.481–3.918] 0 0 0 5.21 [5.21–5.41]
    ON 2, 2, 2 0.000 0.050–0.062 2.668 [1.886–3.790] 0 0 0 4.31 [4.11–4.71]
    cold tune into the guide's small preview OFF 2, 3, 3 1.003–1.006 1.077–1.097 5.021 [4.753–6.182] 0 0 0 — ‡
    ON 3, 2, 2 0.000 0.058–0.062 3.734 [3.637–4.036] 0 0 0 — ‡
    cold tune, then 325 s at the edge (one run) OFF 3 1.006 1.072 4.030 0 0 0 5.51
    ON 3 0.000 0.063 3.836 0 0 0 4.31

    Run k against run k, the start came sooner with the latch in all 10 pairs, by 0.128 to 2.545 s. That is counted from the engine's dispatch; counted from our app's channel change instead, one ON zap (run 1) reached the picture 1.44 s later, because our own channel change before the dispatch took 9.00 s on that run against 7.43 s on its OFF pair. The part the latch touches, first serve → presenting, came sooner by 1.003 to 1.039 s in all 10; the rest is the source: dispatched → first serve, which the latch does not touch, differed by −1.506 to +0.878 s between paired runs. At +60 s the picture sat 0.5 to 1.5 s nearer the edge in the six pairs with a reading on both sides (every reading in the first table: OFF 5.21–5.61 s, ON 4.01–4.71 s). So on the device, as on your Mac, the arm removes the grace and the session stays about that much nearer the edge.

    Rebuilds from a backlog (every first serve full: 6 segments, 6.006 s against the 6 s holdback):

    rebuild arm first serve waited (s) held (s) first serve → presenting (s) start (s) stalls -16832 -12888 behind live 60 s after (s)
    Go to Live after an 8 s pause, rejoining 6 s behind (what we ship) OFF 0.042–0.053 0.000 0.025–0.027 0.125 [0.124–0.127] 0 0 0 6.37, 6.27 §
    ON 0.043–0.046 0.000 0.025–0.027 0.125 [0.117–0.128] 0 0 0 6.62 [6.62–6.72]
    the same, rejoining 5 s behind OFF 0.422–0.665 0.000 0.041–0.053 0.723 [0.520–0.762] 0 0 0 6.11 [6.01–6.11]
    ON 0.668–1.007 0.000 0.042–0.052 0.853 [0.771–1.119] 0 0 0 6.51 [6.11–6.61]
    DVR jump 30 s back OFF 0.041–0.062 0.000 0.035–0.063 0.165 [0.162–0.167] 0 0 0 30.54 [29.79–30.69]
    ON (two runs ¶) 0.039–0.044 0.000 0.066–0.073 0.153, 0.166 0 0 0 28.74, 30.79

    Your least-sure case is not in this data. We ran the rebuild from a 6 s backlog (our Go to Live) and forced a 5 s one, but on this channel at 7.27.3 neither starts bounded: six 1.001 s segments fill the 6 s holdback, and the 5 s rejoin got its sixth segment within the wait (0.42 to 1.01 s). All 17 rebuilds, both arms, served a full cushion, so the latch had nothing to skip. The 5 s rejoin's 0.13 s later median start with the latch is a longer wait for that sixth segment (dispatched → first serve), not the serve (first serve → presenting 0.042–0.052 s against 0.041–0.053 s). A rebuild that starts bounded, where the second grace may have been buying cushion, was not staged: our 2 October example of one (on #670) was a TARGETDURATION 3 seal, and no seal here read 3. A Go to Live that rejoins about 4 s behind should leave five segments (5.005 s) at the first serve on this channel; we can run that both ways if it would help the decision.

    Stalls and errors. Across the 18 ON launches (21 playback sessions), every stats final line reads dropped 0 stalls 0 and no -16832 or -12888 was logged; the 19 OFF launches in the same cells read the same, apart from the run marked †. Zero in 18 still leaves room for a per-launch stall rate of up to about 18 % (Wilson, 95 %), so it says nothing about a rare stall.

    Marked runs.

    • † OFF cold run 1: the channel's source misbehaved from about 29 s after the tune locked. Segments arrived 2.2 to 2.9 s apart from +28.9 s, the picture stalled at +31.2 s, at +36.2 s the source's timestamps jumped back 36.5 s with its parameter sets re-sent (the picture resumed at +36.4 s), and from then until the run ended at +84 s it delivered in bursts with quiet spells of 3.6 to 11.5 s. That run's one stall (+31.2 to +36.4 s) and all four -12888 lines (+42.9 to +71.0 s) fall inside that episode, and its behind-live reading (51.59 s) does not survive the timestamp jump, so it is left out of that column; its start, before the episode, is in.
    • ‡ The guide's small preview has no behind-live reading: our sampler runs only in the full-screen player.
    • § OFF Go to Live (6 s) run 2 reads 0.00 s behind live because our own sampler took its baseline before the rebuilt session had published its clock. That is ours, not a position, and it is left out.
    • ¶ ON jump run 2: our media server answered HTTP 503 to the channel's opens for about 45 s, and the run started late on a plain tune with no backlog to jump into, so it is left out.

    7.24.0 (9bd00968) ran first in each session on the same recipe and reads like OFF: its bounded first serves held the second request 1.012 to 1.020 s (the ten runs in the first table, read from the request times, since 7.24.0 has no such line; the same reading on the ten OFF runs gives 1.012 to 1.021 s, against their own held line's 1.002 to 1.006 s) and went from first serve to presenting in 1.059 to 1.082 s (all 22 bounded first serves in these runs); every stats final line read stalls 0, with no -16832 or -12888.

    Not measured: a Release build, a bounded rebuild, a source with longer segments, more than three runs per cell. Redacted slices on request.

    7.27.3 is our app's engine pin as of today (2026-10-06).

  4. superuser404notfound commented on Oct 6, 2026

    @superuser404notfound
    Owner

    Thank you, this is exactly the data the decision needed, and the pairing (run k against run k, the split into dispatched → first serve and first serve → presenting) made it easy to read.

    Decided: the latch is the default for engine-cut sources in 7.28.2 (637466fa, fix in efdd6e8a). The reasoning, from your tables:

    • The part the latch touches came 1.003 to 1.039 s sooner in all 10 bounded pairs, the same grace the Mac harness removes, and nothing else in the start moved.
    • The cost the arm was held back for, a session nearer the edge, came out at 0.5 to 1.5 s with no stall, -16832 or -12888 in 18 latched launches. Your Wilson bound is fair; the default does not claim more than that.
    • All 17 rebuilds served a full cushion, so the latch did not change them.

    AETHER_FIRST_SERVE_LATCH_ALL=0 now restores the old gate (=1 is a no-op), still read once per process, and both arms keep the repeat live manifest request held line.

    The bounded rebuild offer, taken up. A Go to Live that rejoins about 4 s behind (five segments, 5.005 s at the first serve) is the one case where the second grace could have been buying cushion the window lacks, so that run both ways on 7.28.2 (default against =0) would close the remaining gap. Same columns as above are ideal; stalls, -16832 and behind-live at +60 s matter most there.

    Leaving this open until that run is in.

  5. cmcpherson274 commented on Oct 8, 2026

    @cmcpherson274
    Author

    Here is the run from your comment above: a Go to Live that rejoins about 4 s behind, both ways on 7.28.3 (the default against AETHER_FIRST_SERVE_LATCH_ALL=0; 7.28.3 differs from 7.28.2 only in the #699 demuxer repair, so the live serve path is 7.28.2's), with 7.27.3 beside them, in the columns of our 6 October comment.

    Setup. As in that comment (the same Apple TV, Debug builds and live path), on one 1080p59.94 H.264 + AAC channel, in one session on the morning of 2026-10-08. Each run is a fresh launch: a cold tune, about 20 s of play, an 8 s pause, then Go to Live with our rejoin point moved from the 6 s we ship to 4 s behind the newest data our app holds. One build of 7.28.3 (3cc256a0) serves both arms, with =0 set in the process environment of each =0 launch, in the order default, =0, =0, default, default, =0, =0, default, default, =0; three runs of 7.27.3 (b27f2971) on the same recipe came first. In these runs all 10 repeat lines of the latched launches carry first-serve latch, and none of the 16 from the =0 and 7.27.3 launches does. Every rebuild sealed TARGETDURATION 2 with 1.001 s segments (holdback 6 s), and on every one of these rejoins the first serve waited out the 1.0 s grace on the first request (1.019 to 1.026 s) and then served five segments, in all but one run:

    first live manifest served after 1.024s: 5 segments / 5.005s < 6.000s holdback (TARGETDURATION 2s), fastZap bounded start after 1.001s grace
    

    Columns as before: start is #361 startup 0/8 dispatched → 8/8 presenting of the rebuilt session; held is your repeat line; behind live at +60 s is the reading defined in our earlier comment, taken 60 s after the rebuild (on every run the median of its samples from +30 to +80 s is within 0.30 s of it). These runs end with the app being killed, so there is no stats final line: stalls counts playbackStalled after the press plus any timeControlStatus=waitingToPlay after the rebuilt item first reached playing, and the two codes are counted over the same span. Each rejoined session was watched for 86 to 92 s after its first picture. Median [min–max].

    Go to Live, rejoining 4 s behind runs first serve (segments) held (s) first serve → presenting (s) start (s) stalls -16832 -12888 behind live at +60 s (s)
    7.28.3, default 5 5 in all five 0.000 0.052 [0.042–0.060] 1.135 [1.112–1.150] 0 0 0 5.41 [5.21–5.71]
    7.28.3, =0 4 † 5 in all four 0.599 [0.355–0.886] 0.653 [0.418–0.948] 1.730 [1.492–2.025] 0 0 0 6.16 [5.81–6.21]
    7.27.3 3 5 in all three 0.690 [0.575–0.778] 0.749 [0.633–0.836] 1.823 [1.714–1.904] 0 0 0 6.41, 6.21 ‡

    Run k against run k (runs 1, 2, 3 and 5, five segments on both sides), first serve → presenting was 0.358 to 0.891 s shorter with the default (median 0.603 s), and the picture sat 0.20 to 0.90 s nearer the edge at +60 s (median 0.65 s). Dispatched → first serve, which the latch does not touch, read 1.064 to 1.098 s on every 4 s rejoin of every arm.

    What the second grace was buying here. With =0, and on 7.27.3, the repeat line carries no grace note: in all eight runs it was logged 0 to 2 ms after the engine's producer finalized the sixth segment of the rebuilt window (6 × 1.001 s = 6.006 s, the holdback), so the cushion check released it (VideoSegmentProvider.swift:2625 at 3cc256a0), and the picture followed 39 to 47 ms later. So on this rejoin the old gate did buy the cushion the window lacked (one segment, two on the four-segment run), for 0.36 to 0.89 s depending on where the next cut fell. With the default the picture presented 0.64 to 0.77 s before that sixth segment existed, and none of the five latched sessions logged a stall, a -16832 or a -12888 in the 88 to 92 s that followed.

    The #524 line, as a report. #524 the client is running thin did not print after any Go to Live in this session, on any arm; it printed once each during the cold tune before the pause, in one 7.27.3 run and in one =0 run (1.93 and 1.94 s of fetched runway). In a second session the same morning, 7.27.3 against 7.28.3's default with twelve launches each (cold tunes, cold tunes into the guide's small preview, a channel zap, DVR jumps, a forced engine fault that our app recovers by rebuilding at the playhead, and hand-overs from the preview to full screen; no =0 arm), it printed 10 times on 4 of the 12 latched launches (three cold tunes and one preview; 1.78 to 1.99 s of runway) and on none of the 12 7.27.3 launches. No stall followed any of them; every stats final line in that session reads dropped 0 stalls 0. We report it beside the zero stalls, not as a verdict.

    In that session the default did on ordinary tunes what the arm did on 7.27.3: first serve → presenting 0.051 to 0.058 s on the three cold tunes against 1.066 to 1.079 s on 7.27.3, and 16 of 16 latched repeat lines carry first-serve latch against 0 of 16 on 7.27.3. One full-cushion rebuild there read differently, and we have not separated it: the rebuild after the forced fault (one run each) waited 0.894 s for its sixth segment on 7.28.3 against 0.040 s on 7.27.3, the latched session having stood 4.57 s behind before the fault against 5.67 s. Of the five unlatched fault rebuilds we hold (7.24.0 and 7.27.3, this session and two days earlier), behind live before the fault against the wait for the first serve reads 5.07 s → 0.051 s, 5.17 s → 0.679 s, 5.57 s → 0.597 s, 5.67 s → 0.040 s and 6.48 s → 0.047 s: two waited for their sixth segment and three did not, with no threshold between them, so the latch is at most one candidate and we have not separated it; it is on our list to repeat. Our shipped Go to Live (6 s behind) served six segments after 0.04 s on both 7.28.3 arms (one run each; start 0.117 s default, 0.107 s =0), so there the latch had nothing to skip, as before.

    Limits. One channel, one session, Debug builds, about 90 s after each rejoin. Zero stalls in five latched rejoins still allows a per-rejoin stall rate of up to about 43 % (Wilson, 95 %); across all 23 latched live launches we ran on the Apple TV at this pin, none of which stalled, it is up to about 14 %. Not measured: a Release build, a source with longer segments or a TARGETDURATION 3 seal, a second channel.

    Marked runs.

    • † =0 run 4's first serve held four segments (4.004 s) rather than five, so it is left out of that row: held 0.739 s (released at the sixth segment like the others), first serve → presenting 0.798 s, start 1.885 s, no stall or code, 6.51 s behind at +60 s.
    • ‡ 7.27.3 run 1 reads 0.00 s behind live: as in the § note of our earlier comment, our sampler took its baseline 1 ms before the rebuilt session published its clock. That is ours, not a position, and it is left out.

    7.28.3 is our app's engine pin as of today (2026-10-08).

  6. superuser404notfound commented on Oct 8, 2026

    @superuser404notfound
    Owner

    Thank you, this closes the gap the default was decided without. Separating the latch's share (first serve → presenting) from the source's share (dispatched → first serve) made it easy to read again.

    The bounded rebuild, read. The run shows what the second grace was buying: on a 4 s rejoin the old gate (and 7.27.3) released the repeat request when the sixth segment was finalized, so it bought exactly the missing cushion, one segment, for 0.36 to 0.89 s. With the latch the picture presents before that segment exists. In this run that cost nothing measurable: no stall, -16832 or -12888 in the five latched rejoins over about 90 s each, and 0.65 s (median) nearer the edge at +60 s. So the cost is the one we expected: a slightly thinner start, with no stall to show for it on this source. The latch stays the default, and AETHER_FIRST_SERVE_LATCH_ALL=0 stays as the opt-out.

    The #524 line. It is the expected signature of the same trade, not a contradiction. The threshold is a flat 2.0 s, calibrated on a 6 s-segment source whose healthy sawtooth bottoms out around 3 s. A session that sits about 1 s nearer the edge on 1.001 s segments will dip just under it (your 1.78 to 1.99 s), while its next delivery is still one second away. The line is a warning that the margin is thin, not a stall, and your stats final lines agree. I am not moving the threshold on this data. If it starts to precede stalls on a source with longer segments, that is the place to look again.

    The fault rebuild that waited 0.894 s. Agreed that it is not separated: your five unlatched fault rebuilds already split two waits against three without a threshold, so the latch is no more than a candidate. Note that the latch cannot add to dispatched → first serve, which is where that 0.894 s sits. It only releases the repeat request after the first serve. What the latch can do is move the session nearer the edge before the fault (your 4.57 s against 5.67 s), and a rebuild at the playhead with less backlog behind it waits longer for its sixth segment. Your unlatched rows do not line up on that alone, so I read it as a plausible path, not a finding. If the repeat shows it, it is the same trade showing up at the next rebuild, a fraction of a second paid once, and still no stall.

    Closing this as decided: the default shipped in 7.28.2, and the remaining case is now measured. A Release build, a longer-segment source or a TARGETDURATION 3 seal are welcome here or in a new issue if any of them reads differently.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions