Repository navigation
feat(buffer): bound the opt-in prefetch in bytes, raise the window ceiling to 2700 (#207) - #212
Merged
Conversation
…iling to 2700 (#207) The 150-segment ceiling on LoadOptions.forwardBufferSegments (#102) silently capped a host's "buffer without limit" option: any request above it clamped down, so a user who deliberately opted into pre-buffering a whole film for a flaky WAN still stalled once the connection dropped for longer than ~10 min of content. Raising the ceiling alone would have been unsafe. SegmentCache.pruneOutsideWindow never evicts the hard window, so the retention budget (min(2 GiB, a quarter of the tmp volume's free space), the only guard that keeps a nearly full device playable) bounds just the extras outside it. That holds by construction for the historical windows (10 segments ~ 100 MB, the 150 ceiling ~ 1.5 GB), but a window spanning a whole film would make the window itself the footprint and put ~18 GB of 4K HEVC on the volume unchecked. A failed segment write degrades to a cache miss and stalls playback, i.e. exactly the failure the option exists to prevent, with disk instead of network as the cause. So the bound moves from segments to bytes: - The ceiling becomes 2700 (~3 h at 4 s), a sanity bound against accidental values that covers a whole feature film, so hosts can pass Int.max. Floor (4) and the nil default (10) are unchanged and 150 still passes through, so sessions that do not opt in are unaffected. - Windows past the historical 150 are an explicit opt-in, so the retention budget drops its 2 GiB default cap for them and keeps the quarter-of-free-space clamp, which is what actually protects the volume. - The producer parks once its race-ahead (bytes at or above the consumer's target) has filled that budget, while the consumer still has PrefetchDiskBudget.minAheadSegments of produced content ahead of it. The extras eviction that follows the advancing playhead releases the park, so the prefetch tracks the budget instead of the source length. Counting only bytes at or above the consumer target, rather than the whole window, keeps retained backward history (which the extras eviction already bounds) from throttling a producer whose actual race-ahead is a handful of segments. The park deliberately has no wedge breaker: it only ever holds with a safe lead of produced content, and a short lead keeps producing regardless of the budget, so bounding disk can never win over playback. Reported with a ceiling-raise patch by fxndxs; the ceiling change and its test deltas are taken from that patch. Co-Authored-By: findussoft <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01M7tL3aHF9rGKfHCSE3DhJ4
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.
Follow-up to #102, addressing #207.
Why the ceiling alone was not enough
SegmentCache.pruneOutsideWindownever evicts the hard window, so the retention budget (min(2 GiB, a quarter of the tmp volume's free space)) bounds only the extras outside it. That is correct for the historical windows (10 segments ~ 100 MB, the 150 ceiling ~ 1.5 GB), which fit under the budget by construction. A window spanning a whole film makes the window itself the dominant footprint and the budget unreachable: ~18 GB of 4K HEVC lands on the volume unchecked, andSegmentCache.storedegrades a failed write to a cache miss, i.e. a stall. That is the failure the option exists to prevent, with disk instead of network as the cause.What this does
clampedForwardWindowceiling 150 -> 2700 (~3 h at 4 s), a sanity bound that covers a whole feature film, so a host can passInt.max. Floor (4) and the nil default (10) unchanged; 150 still passes through.vodRetentionBudgetBytesdrops its 2 GiB default cap for them. The quarter-of-free-space clamp, which is what protects the volume, always applies, and an unknown capacity keeps the conservative cap.PrefetchDiskBudget: the producer parks once its race-ahead (bytes at or above the consumer's target) has filled the budget, while the consumer still hasminAheadSegments(10) of produced content ahead of it. The extras eviction that follows the advancing playhead releases the park, so the prefetch tracks the budget instead of the source length.Counting only bytes at or above the consumer target, rather than the whole window, keeps retained backward history (already bounded by the extras eviction) from throttling a producer whose actual race-ahead is a handful of segments. The park has no wedge breaker by design: it only holds with a safe lead of produced content, and a short lead keeps producing regardless of the budget, so bounding disk can never win over playback.
Behavior for hosts that do not opt in
Unchanged.
forwardBufferSegmentsnil or <= 150 keeps the same budget, and the park's condition (race-ahead bytes >= budget) is unreachable at those window sizes.Tests
16 new tests (999 total, all green): budget sizing with and without the relaxed cap, the park decision (no budget / under budget / at budget / short consumer lead),
SegmentCache.forwardBytessemantics, the headroom park primitive including release as the playhead advances, and a regression guard that retained history never withholds headroom. Ceiling test deltas taken from the reporter's patch.Verified:
swift test999 passed,swift build -Xswiftc -strict-concurrency=completeclean, tvOS Simulator build succeeded. Not yet device-verified with a real opt-in prefetch session.Reported with a ceiling-raise patch by @fxndxs.