You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Buffering causes the application to crash when handling large files #31
For large files (50–80 GB) on Apple TV 4K, buffering causes memory exhaustion.
After playback starts, memory usage can easily spike to around 1.4 GB. In most cases, the application crashes before the system has a chance to reclaim memory. I tried modifying the engine locally to buffer fewer segments, which helped somewhat. However, the problem reappears when subtitles are enabled — at that point, the application is usually terminated within a short time.
If I understand the architecture correctly:
The main demuxer downloads the stream and converts it into video and audio HLS segments.
The side demuxer downloads the same stream again, solely to extract subtitle packets.
This appears to result in an unavoidable application crash when dealing with files of this size.
Steps to reproduce
Apple TV 4K 2nd generation
Try to open big stream (80GB)
2.Try to activate subtitles
Thanks for the detailed report. There were two separate problems here.
The subtitle part is fixed as of f2e3260. Your read of the architecture was correct: the side demuxer that extracts subtitle packets opened a second connection and read to EOF at line rate, so it re-downloaded the whole file in parallel with playback and kept every future bitmap cue (each one holding a decoded RGBA image) in memory. The reader is now paced against the playhead: it reads at most 90 seconds ahead, then parks, and TCP backpressure throttles the second connection down to playback rate. For a PGS track this bounds cue memory to a few minutes around the playhead regardless of file size.
The 1.4 GB spike without subtitles is a different story. The segment pipeline itself is disk-backed on your commit (segments are written to disk and served via sendfile, not held on the heap), so I'd like to narrow down what's growing. Could you share:
Is the file Dolby Vision (profile 8.1), or plain HDR10? There is a suspected AVFoundation-internal leak in the per-frame HDR metadata path (~3 MB/s) that only affects DV sources.
How are you measuring the 1.4 GB (Xcode memory gauge vs. a jetsam crash report)? If you have a jetsam report, the pageIns/phys_footprint numbers would help.
Does the spike reproduce with the same file when you start playback and immediately pause?
If you can update to current main and retest with subtitles enabled, that would confirm the first fix on your setup.
Thanks for the detailed report. There were two separate problems here.
The subtitle part is fixed as of f2e3260. Your read of the architecture was correct: the side demuxer that extracts subtitle packets opened a second connection and read to EOF at line rate, so it re-downloaded the whole file in parallel with playback and kept every future bitmap cue (each one holding a decoded RGBA image) in memory. The reader is now paced against the playhead: it reads at most 90 seconds ahead, then parks, and TCP backpressure throttles the second connection down to playback rate. For a PGS track this bounds cue memory to a few minutes around the playhead regardless of file size.
The 1.4 GB spike without subtitles is a different story. The segment pipeline itself is disk-backed on your commit (segments are written to disk and served via sendfile, not held on the heap), so I'd like to narrow down what's growing. Could you share:
Is the file Dolby Vision (profile 8.1), or plain HDR10? There is a suspected AVFoundation-internal leak in the per-frame HDR metadata path (~3 MB/s) that only affects DV sources.
How are you measuring the 1.4 GB (Xcode memory gauge vs. a jetsam crash report)? If you have a jetsam report, the pageIns/phys_footprint numbers would help.
Does the spike reproduce with the same file when you start playback and immediately pause?
If you can update to current main and retest with subtitles enabled, that would confirm the first fix on your setup.
The persistent reader's sliding window is a Data that gets appended at the tail and trimmed at the front with removeFirst. It turns out Data.removeFirst only advances the slice's lower bound: the backing storage stays addressed from its origin, and the append-side growth reallocates it to fit the slice's ever-increasing upper bound. So while window.count held steady at ~20 MB, the single backing allocation grew with every byte ever streamed through the connection, which at your 80 Mbps is ~14 MB/s, matching both your Xcode gauge and the realloc stack you captured. Paused playback stops the stream, which is why it looked stable there. The trim now re-bases the window into fresh compact storage; a standalone repro of the pattern went from +513 MB footprint per 512 MB streamed to +9 MB flat.
With this and the subtitle-pacing fix from 3.0.0, both halves of your report should be resolved. If you can retest your 87 GB file (with and without subtitles) on 3.0.1 or current main, I'd expect the memprobe's mallocMB to plateau after the first minute. I'll keep this open until you can confirm.
Activity
superuser404notfound commentedon Jun 10, 2026
Thanks for the detailed report. There were two separate problems here.
The subtitle part is fixed as of f2e3260. Your read of the architecture was correct: the side demuxer that extracts subtitle packets opened a second connection and read to EOF at line rate, so it re-downloaded the whole file in parallel with playback and kept every future bitmap cue (each one holding a decoded RGBA image) in memory. The reader is now paced against the playhead: it reads at most 90 seconds ahead, then parks, and TCP backpressure throttles the second connection down to playback rate. For a PGS track this bounds cue memory to a few minutes around the playhead regardless of file size.
The 1.4 GB spike without subtitles is a different story. The segment pipeline itself is disk-backed on your commit (segments are written to disk and served via sendfile, not held on the heap), so I'd like to narrow down what's growing. Could you share:
If you can update to current main and retest with subtitles enabled, that would confirm the first fix on your setup.
RomanLiberda commentedon Jun 10, 2026
Size: 87.18 GB
Bitrate: 80.0 Mb/s
Video: HDR10
Video Decoder: VideoToolbox HEVC (HW)
Audio Decoder: Stream-copy (AC3)
Mode: Native (AVPlayer)
Duration: 2:25:21
Tracks: 7 audio tracks • 3 subtitle tracks
Just the Xcode
No, when the video is paused it seems to be stable
Here is the memprobe from the console:
[AetherEngine] memprobe t=60s rss=466MB vmInt=427MB vmExt=33MB vmCmp=527MB vmIOS=0MB physFP=978MB mallocBlocks=739241 mallocMB=1865 avioFetchedMB=850 cacheCount=12 cacheMB=419 packetsWritten=1901 audioFifo=0 abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=694 muxCuts=20 srvConns=1 srvBytesMB=520 srvSfMB=439 pktAlive=3 pktTotal=4698 subCues=20 audioTracks=7 subTracks=3 subActive=false avBufAhead=5.7s avBufBehind=31.4s
The mallocBlocks=739241 looks suspicious to me, I tried to run audit via Instruments and this is the stack trace of the Malloc that has over 1GB
realloc
malloc_type_realloc_outlined
__DataStorage.ensureUniqueBufferReference(growingTo:clear:)
__DataStorage.resetBytes(in:)
Data.InlineSlice.count.setter
Data.Representation.count.setter
AVIOReader.appendPersistentData(:generation:)
PersistentReadDelegate.urlSession(:dataTask:didReceive:)
@objc PersistentReadDelegate.urlSession(:dataTask:didReceive:)
__77-[__NSCFURLSessionDelegateWrapper dataTask:didReceiveData:completionHandler:]_block_invoke_3
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_lane_serial_drain
_dispatch_lane_invoke
_dispatch_root_queue_drain_deferred_wlh
_dispatch_workloop_worker_thread
_pthread_wqthread
start_wqthread
superuser404notfound commentedon Jun 10, 2026
That Instruments trace was exactly what was needed, thank you. Root cause found and fixed in release 3.0.1 (https://github.com/superuser404notfound/AetherEngine/releases/tag/3.0.1).
The persistent reader's sliding window is a
Datathat gets appended at the tail and trimmed at the front withremoveFirst. It turns outData.removeFirstonly advances the slice's lower bound: the backing storage stays addressed from its origin, and the append-side growth reallocates it to fit the slice's ever-increasing upper bound. So whilewindow.countheld steady at ~20 MB, the single backing allocation grew with every byte ever streamed through the connection, which at your 80 Mbps is ~14 MB/s, matching both your Xcode gauge and the realloc stack you captured. Paused playback stops the stream, which is why it looked stable there. The trim now re-bases the window into fresh compact storage; a standalone repro of the pattern went from +513 MB footprint per 512 MB streamed to +9 MB flat.With this and the subtitle-pacing fix from 3.0.0, both halves of your report should be resolved. If you can retest your 87 GB file (with and without subtitles) on 3.0.1 or current main, I'd expect the memprobe's mallocMB to plateau after the first minute. I'll keep this open until you can confirm.
RomanLiberda commentedon Jun 10, 2026
Nice 👍 It looks good to me now! Memory leak is gone.
refactor: remove dead in-band mov_text/tx3g subtitle muxing
Release consumed bytes in the held connection's chunked decoder