Repository navigation
Description
Split out of the Sodalite#49 / #339 device session, which measured the numbers this rests on.
What happens now
An engine HDR/DV write is followed by a pre-flight waitForSwitch(), and only when that returns does loadNative run. The switch and the load are therefore serialised, although only the first frame has to wait for the panel, not the demuxer, the local HLS server or the AVPlayerItem.
Twelve measurements on an Apple TV 4K (3rd gen), tvOS 26.5, with the mode-switch notifications actually arriving (#339): a switch takes 2779 to 2898 ms, dynamic-range and range-plus-rate alike, and loadNative takes ~850 ms on a LAN source.
Why it currently looks fine
Stage 2's cap is 2000 ms, so the pre-flight gate always breaks out with the panel still switching, the load runs during the remaining ~880 ms, and the play gate waits out the rest:
cap 2000: pre-flight breaks +2020, load ~850 ms, play() at ~+2918 (switch ends +2892)
cap 4000: pre-flight ends +2892 on the notification, load ~850 ms, play() at ~+3740
The too-small cap is an accidental half-parallelisation, and it is the only reason the startup time is good. "Fixing" the cap to match the measured switch costs a full load, ~820 ms. That trap is now written on stage2CapMs.
What to build
Start the load concurrently with the switch and await the settle before play(), so cold start is max(switch, load) rather than cap + load. On this panel that is a wash today; it pays where the load is slow (remote origin, cold cache, large MKV) and on fast-switching panels (QMS), where the pre-flight now returns in milliseconds and the load is the only remaining cost.
load 2000 ms, switch 2900 ms: 2000 + 2000 = 4000 ms today, max(2900, 2000) = 2900 ms concurrent
load 850 ms, QMS switch 200 ms: 200 + 850 = 1050 ms today, max(200, 850) = 850 ms concurrent
The constraint that keeps it sequential
waitForSwitch's own note: starting the decode mid-write races an AVPlayer error on DV Profile 8.1. That is a real failure and it is the one path that cannot be verified on the hardware available here (the test panel does not do DV).
Suggested cut: keep DV sequential, run HDR10 / HLG / SDR concurrently. The unverifiable path then stays byte-for-byte unchanged, and the change is confined to formats that can be measured. Verifying the gain needs a slow origin (Scripts/throttle-origin.py) since a LAN load is dominated by the switch.
Not urgent
Nothing is broken. This is startup latency in a shape where the current good behaviour depends on a constant that is not documented as doing that job, which is exactly how the next well-meant cap change breaks it.
Activity
superuser404notfound commentedon Aug 9, 2026
Second coupling, found while sizing this: the pre-flight wait does not only gate
play(), it gates the routing decision.AetherEngine.swiftreadspanelHDRAfterHandshake = displayCriteria.currentPanelIsHDR()immediately after the handshake block, and that value decidesvideoFormatand is handed toloadNativeaspanelIsInHDRMode, which is whatresolveUseMasterPlaylistuses to choose a PQ master over media-direct. Reading it while the switch is still running returns the pre-switch state, so a naive concurrent load would route an HDR title as SDR: no HDR signalling, silently, for the whole session. That is the failure shapepanelPresentsHDRexists to prevent, and the kind that surfaces weeks later.So the cut is not "DV sequential, everything else concurrent". It is:
panelProvenToEngageHDR), or an SDR route: the routing answer is known without measuring, so the load can run during the switch.That keeps the concurrency where it is safe and leaves the one case that cannot be answered early alone. It also means the win is smaller on a cold process than the headline numbers suggest, and largest exactly where it matters, on repeat playback with a slow origin.
Worth checking before building: whether
panelProvenToEngageHDRalone is a strong enough answer for the master/media choice, or whetherresolveUseMasterPlaylistneeds its own explicit input rather than a flag that means two things.superuser404notfound commentedon Aug 9, 2026
Closing this as analysed and deliberately not built. The numbers do not support it, and writing down why is more useful than leaving it open.
The gain, filtered three times
Only the HDR/DV path. A rate-only write takes no pre-flight at all, so its load already runs during the switch. Device run, SDR 25p: item ready at +400 ms, gate released at +2880 ms, fully overlapped as it stands.
The pre-flight is capped at 2 s, so the ceiling on this is 2 s, not the ~2.9 s of a switch.
And it is zero until the load is slow. With measured numbers (switch 2890 ms, load 850 ms):
It turns positive somewhere around 900 ms of load time and reaches the full 2 s only at ~2.9 s of load.
What the routing coupling costs on top
Per the comment above, the concurrent path is only safe when the routing answer is already known, that is when
panelProvenToEngageHDRis set. That flag is instance state, so it is unset for the first HDR title after every app launch, which is exactly the load that would benefit most. Anyone who plays one title per sitting would never reach the concurrent path at all. Persisting the proof would fix that and introduce a worse failure: a stored "this panel does HDR" is wrong the moment the TV is replaced.And the verification is a race
The regression that matters is not the latency, it is reading the panel state before the switch settles and routing an HDR title as SDR for the whole session, silently. Proving the absence of that needs repeated cold-start runs on hardware, and a race that is not reliably lost on one panel and one server is not reliably won either.
So: a gain bounded at 2 s, restricted to HDR starts with a genuine mode change, a slow origin, and a second-or-later title in the same app session, against a change touching two couplings whose failure mode is a quiet loss of HDR. Not a good trade today.
Worth reopening if someone reports slow cold starts on a remote origin with HDR content, which is the one profile where this pays. The measurements are all here.
fix(display): serve an unproven HDR master after the mode switch, not…
badrabbit commentedon Oct 16, 2026
This is the report the closing comment asked for: slow cold starts on a remote
origin with HDR content.
Apple TV 4K (3rd gen), tvOS 27.2, source is a Plex server over HTTP on the LAN,
Dolby Vision title,
AVPlayerViewControllerhost, AetherEngine 7.38.1. Measuredfrom the engine's own log (relative seconds):
[Demuxer] open timings … find_stream_info 930ms, total 1023ms[DisplayCriteria] SET: format=dolbyVision codec=dvh1 rate=23.976panel proven to engage HDR (headroom 1.20)proceed after cap (start in-gate after 11ms, total 2053ms; … most likely already in the target mode)serving on …/master.m3u8seg64: served 17135489 B (wait=648.5ms)switch settled via modeSwitchEnd (… switch 2889ms end to end)seg65: served 32430776 B (wait=1346.5ms)timeControlStatus=playingSo the two steps are strictly serialised: the HLS server comes up 115 ms after
the pre-flight cap releases, and the segment build (2.0 s for the first two
segments of a 4K HEVC title with peaks near 96 Mbit) starts only then. The panel
finishes switching at 3.952 s, while playback starts at 5.469 s — about 1.5 s of
the cold start sits behind a switch that had already completed.
On the "gain is zero when the load is fast" point: that is the part that does not
hold here. The load is not fast on this route — two segments of this bitrate cost
2.0 s to cut, and tightening
probesizeto 4 MB (which tookfind_stream_infofrom 930 ms to roughly 150 ms) only moved the whole sequence forward, it did not
overlap anything.
On the HDR-routing concern from the closing comment: in this session the panel
readout was already authoritative well before the cap expired —
panel proven to engage HDR (headroom 1.20)at 1.466 s, 430 ms after the writeand 1.6 s before the gate released. The gate's own log line says as much
("most likely already in the target mode").
What makes this painful in practice is that it is paid on every start. Leaving
playback resets the criteria, so the next title writes them again and gets
.willSwitch— the.unchangedshortcut needsdidApply && managerHoldsCriteria,and neither survives a stop. The result is a visible 5+ second start on a title
that the panel is ready for after 2.9 s.
superuser404notfound commentedon Oct 19, 2026
Thank you, this is exactly the profile the closing comment asked for, and the numbers hold up against the code. Reopening.
Checked against
main:loadNativeonly starts once it returns, so the 115 ms betweenproceed after capandserving on …/master.m3u8is the HLS session coming up behind the gate, as described.reset()clears the applied criteria on stop, so every title writes them again and gets.willSwitch. The cost is per start, not per app launch.The part that changes the design: the routing decision the closing comment worried about is not needed for the expensive work. Inside
HLSVideoEngine.start(), the demuxer seek, the segment plan, the local server and the producer that cuts the first segments all run before the master-or-media choice, andpanelIsInHDRModeis read only for that choice, at the very end. So the cut is:AVPlayerItem,play().AVPlayer sees nothing before the gate, so the Dolby Vision mid-write race and the "HDR routed as SDR" failure both stay exactly where they are today, and the cut does not need to exclude DV or the first title after launch. On this log it should move
playingfrom ~5.5 s to just after the switch ends (~4.0 s).Separately, the
proceed after cap … most likely already in the target modeline is wrong in this session: the switch was seen starting 11 ms into the gate and only ended 860 ms after the cap. A latched HDR proof says the panel can engage HDR, not that it already has, once a start was observed. That line gets fixed with the change.Will post here when there is a build to test.
Merge feat/ae348-load-during-switch: produce the first segments while…
superuser404notfound commentedon Oct 20, 2026
Released in 7.43.0 (
cb25fe83, merged as4467df77).Verified on an Apple TV 4K (3rd gen) with a Dolby Vision Profile 8.1 title, first title after launch: the local server was up 74 ms after the criteria write, every segment was cut inside the 2.9 s switch, and
playingfollowed 218 ms aftermodeSwitchEnd, routed to the master as before (useMaster=true,dvh1.08.07/db1p). That clip was small, so it shows the order more than the size of the gain; a retest on the Plex route with the ~96 Mbit/s title would show the full effect. The lines to compare areprepared/serving onagainstswitch settled via modeSwitchEnd, and the gap from there totimeControlStatus=playing.Live loads keep the serial order, as do Profile 7 sources that may take the dual-layer route.
perf(load): produce the first segments while the panel switches (supe…
Merge PR #830: session cache byte budgets and lifecycle status
cmcpherson274 commentedon Oct 22, 2026
A data point for 7.43.0's change from an Apple TV on tvOS 27.0, read on the lines you named:
prepared/serving onagainstswitch settled via modeSwitchEnd, and from there totimeControlStatus=playing. It is not the retest on the Plex route you mentioned, but a heavy clip from a Jellyfin server on the LAN. We ran 7.44.0, which includes the change, beside 7.36.0. On an HLG Dolby Vision clip resumed near its end,playingcame 1.83 s sooner after the criteria write: 380 ms after the switch ended instead of 2,240 ms.Setup. Apple TV 4K (3rd generation,
AppleTV14,1), tvOS 27.0 (24J361); the switch times in the issue text were measured on tvOS 26.5. Debug builds of our app, 7.36.0 and 7.44.0 in one evening (20 October, US Eastern), each run in a fresh process; 7.44.0 with none of its optional traits enabled, and FFmpegBuild also differs between the two (3.7.1 and 3.9.0). Full-screen VOD played direct through our loopback route; the engine writes the display criteria itself. 19 starts per version; one HDR10 start per version, in which our bench's HDMI output dropped, is left out of the per-title figures.The switch read 2,897.5 ms end to end (median; 2,878 to 2,929 ms over 38 starts), and the 2.0 s pre-flight cap released before it ended on every start. The panel never read as proven (
provenHDR=nobefore each write), and both versions loggedunproven HDR master waits for the running switch to end before it is served (#667)on all 19 starts.The lines for the HLG Dolby Vision Profile 8.4 clip (3840x2160 at 59.04 fps, 17.5 s long, resumed at 12.48 s; its next two segments 25.0 and 51.8 MB), 3 starts per version, in ms after
[DisplayCriteria] SET:, median [range], 7.36.0 → 7.44.0:prepared:serving onplayingplayingSwitch end →
playingon the other five titles, median ms, 7.36.0 → 7.44.0: Kinda Pregnant, Dolby Vision 8.1 (3 starts per version) 915 → 833; an HDR10 film (3) 1,289 → 895; a Dolby Vision 8.1 test clip (7) 1,329 → 1,215; Hotel Chevalier, Dolby Vision 7 (1) 818 → 434; F9, Dolby Vision 7 with a full enhancement layer (1) 1,255 → 517.prepared:came after the switch end on all 19 starts. On 7.44.0 it came 4 to 52 ms after the write, andserving oncame 0 to 5 ms after the switch end (median 3 ms) on all 19.[HLSSegmentProducer] init.mp4 capturedcame before AVPlayer'sGET /init.mp4on 19 of 19 starts on 7.44.0 and 3 of 19 on 7.36.0.7.44.0 is our app's engine pin as of today (2026-10-21).
superuser404notfound commentedon Oct 24, 2026
Thank you for the measurement. It is the order the change was meant to produce, on a second box and on tvOS 27.0:
prepared:moved from after the switch end to 4 to 52 ms after the write, andinit.mp4 capturednow lands before AVPlayer'sGET /init.mp4on every start.Two notes on reading the table:
serving onsitting 0 to 5 ms after the switch end is the tvOS 27: an HDR master served during the display mode switch is refused (-11868), costing the master for every HDR title #667 hold, not the load. WithprovenHDR=noan HDR master is not served while a switch is running, so on your bench the switch end is the earliest point AVPlayer can see anything. The 380 ms after it is AVPlayer's own first fetch of two segments that are already cut (25.0 and 51.8 MB on that clip).panelProvenToEngageHDRis held for the life of the engine instance. If each of the 19 starts ran in its own process,provenHDR=nobefore every write is expected. If several shared a process, the panel on that bench never raisedcurrentEDRHeadroomabove 1.0, and the tvOS 27: an HDR master served during the display mode switch is refused (-11868), costing the master for every HDR title #667 hold will stay on every start there. That is the intended behaviour for such a panel, not a regression.The smaller gain on the Dolby Vision 8.1 titles fits the same picture: their first segments were cheap to cut, so there was less work to move into the switch.
Leaving the issue open for the retest on the Plex route with the ~96 Mbit/s title, which is the case the change was sized against.
fix(display): every HDR master waits for a running switch, proven or …
fix(display): every HDR master waits for a running switch, proven or …