Repository navigation
Description
What happened?
During normal VOD playback, process memory climbs without bound until the host app hits iOS's jetsam memory limit and gets killed. The engine's own memprobe diagnostic shows the growth is not in the bounded AV packet cache (cacheMB, which stays small and tracks video bytes downloaded linearly) — it's in raw heap allocations (mallocMB), and it correlates with subtitle track count (subTracks), not with playback time or bytes transferred.
Root cause: SubtitlePacketStore (Sources/AetherEngine/Subtitles/SubtitlePacketStore.swift) caps retained packets at 32MB per stream (perStreamByteCap, line 27), but the subtitle tap harvests packets for every subtitle stream index the demuxer exposes, not just the one the host has selected (AetherEngine+Loading.swift:935-938 for the software host, Video/HLSVideoEngine.swift:286-287 for the other path). Nothing caps the total across streams. On a source with many embedded subtitle tracks (99, in our repro), each stream independently climbs toward its own 32MB ceiling; with enough bitmap/PGS tracks (the store's own comment notes these are the expensive kind — "a bitmap track keeps a wide trailing window" vs. text tracks staying far below the cap), aggregate retention scales with track count and reaches multiple gigabytes.
Steps to reproduce
- Load a VOD source with a large number of embedded subtitle tracks (our repro case: 99 tracks, mostly bitmap-based) through either playback path.
- Play normally for a few minutes.
- Watch the engine's own
memprobelog:mallocMB(andphysFP) climbs steadily, disproportionate tocacheMBand unrelated to bytes downloaded. - On one of our two test devices, the climb was visible within the first ~3 minutes; on the other, after about ~20 minutes — consistent with track count/subtitle format mix driving the rate, not elapsed time.
AetherEngine version or commit SHA
5.14.0 / 396d138
Host app
Custom / my own integration
Platform
iOS
OS version
iOS 27 (iPhone 16 Pro Max); iPadOS 26.5.1 (iPad 10th generation)
Device / chip
iPhone 16 Pro Max; iPad (10th generation)
Playback path
Both — the bug is in the shared SubtitlePacketStore, tapped by both the software host (AetherEngine+Loading.swift:935-938) and HLSVideoEngine (Video/HLSVideoEngine.swift:286-287).
Source media (for playback bugs)
Not captured via ffprobe for this report — what we have is the engine's own memprobe telemetry showing subTracks=99 on the affected title. Happy to pull exact container/codec details if useful, but the mechanism reproduces on any source with a large number of subtitle streams, particularly bitmap/PGS ones.
Error codes / log lines
Host app's own VOD disk/memory cache was ruled out first — its accounting stayed flat and tracked normal download rate throughout the run. AetherEngine's memprobe on the same run:
t=30s mallocMB=149 cacheMB=39 subCues=34 subTracks=99 physFP=311MB
t=150s mallocMB=197 cacheMB=118 subCues=52 subTracks=99 physFP=289MB
t=180s mallocMB=368 cacheMB=145 subCues=72 subTracks=99 physFP=447MB
t=210s mallocMB=790 cacheMB=158 subCues=83 subTracks=99 physFP=917MB
t=240s mallocMB=1241 cacheMB=168 subCues=91 subTracks=99 physFP=1367MB
t=300s mallocMB=1872 cacheMB=192 subCues=107 subTracks=99 physFP=1977MB
Anything else
Suggested fix: add an aggregate byte budget across entriesByStream in SubtitlePacketStore, mirroring the existing per-item cap (evict oldest entries from the least-recently-touched non-selected stream first once the aggregate budget is exceeded — same two-tier pattern as the existing per-stream eviction in appendLocked). Alternatively/additionally, consider not harvesting packets at all for subtitle streams that aren't currently selected and aren't queued by SubtitleForwardPrefetcher.
99 tracks × up to 32MB/track ≈ 3.2GB theoretical ceiling, which lines up with the observed climb above. Happy to provide more device logs or test further if useful.
Activity
superuser404notfound commentedon Jul 20, 2026
Fixed in 5.15.5 (just released).
Thank you for an unusually complete report. The
memprobetrace, ruling out the host cache layer by layer, and pointing straight atperStreamByteCapvs. the aggregate acrossentriesByStreammade the root cause unambiguous.Your analysis was exactly right: the per-stream 32MB cap was the only bound, and both the pump tap and the forward prefetcher (#151) harvest every embedded subtitle stream into the session store so a track switch backfills instantly without a side demuxer (#112). With 99 tracks each climbing toward its own ceiling, aggregate retention scaled with track count toward ~3.2GB, which matches the
physFPcurve you captured.The fix follows your first suggestion (the two-tier eviction): an aggregate byte budget (96MB) across all streams on top of the per-stream cap.
I kept the harvest-all behavior rather than dropping non-selected streams (your alternative), so #112's instant selection is preserved for the normal case; only cold, long-untouched tracks on pathological many-track sources get evicted, and they re-harvest if selected later.
If you can retest on 5.15.5 with the same run,
mallocMB/physFPshould plateau instead of trackingsubTracks. The offer of exact container details is appreciated, but not needed here: the bound is independent of format. Thanks again for the detailed telemetry.G00380316 commentedon Jul 20, 2026
Thanks for the swift action, Testing now 5.15.5 now
G00380316 commentedon Jul 21, 2026
Confirmed fixed on 5.15.5. Retested the same repro case (subtitle active,
subTracks=99) —mallocMB/physFPplateau as expected instead of trackingsubTracks, no more runaway growth tied to subtitle activity.Separately: we're chasing a different memory growth pattern on the same device/title (VOD-cache playback path specifically, subtitle inactive this time —
subActive=false/subCues=0throughout) that clearly isn't this bug. Ruled out the obvious candidates on our end (disk-cache accounting, a reconnect storm,SegmentCache) and confirmed via Instruments that it isn't showing up in tracked malloc/anonymous-VM allocations either, so it may be sitting in an area Instruments' Allocations tool doesn't attribute cleanly. Flagging only for context in case it turns out related down the line — not attributing it to this fix, and not filing it yet since we don't have a confident root cause. Thanks again for the quick turnaround on this one.superuser404notfound commentedon Jul 21, 2026
Confirmed on my side too, and thanks for closing the loop with the plateau trace. Closing this as fixed in 5.15.5.
On the separate VOD-cache growth you flagged: the fact that it does not show up in Instruments' tracked malloc / anonymous-VM is itself the strongest clue. The Allocations instrument only attributes heap and anonymous VM. It does not account for IOSurface-backed pixel buffers (VideoToolbox decode output) or CoreMedia block/sample-buffer backing, which live in IOKit-mapped and purgeable regions. That is exactly where a native decode/playback path can retain memory that both
mallocMBand the Allocations total miss whilephysFPkeeps climbing.Two things that would pin it independently:
vmmap --summary <pid>sampled over time, or VM Tracker enabled in Instruments, and watch the IOSurface / IOKit / CoreMedia region sizes rather than the Allocations total. If the growth is there, it narrows to the decoder/pixel-buffer side and rules out any host cache for good.If the region-split trace confirms it climbs on IOSurface/CoreMedia, please open a fresh issue with that
vmmap --summarydelta plus the samephysFPcurve. It is a different subsystem from this one and deserves its own thread. The careful isolation you already did rules out most of the false leads, so a fresh trace should land close to root cause.(Current latest is 5.16.0, but that release only touches the live-TV blocking-reload path, nothing on VOD, so no need to jump versions for this.)
G00380316 commentedon Jul 21, 2026
Thanks will do !!!
fix(subtitles): bound SubtitlePacketStore memory across all streams (s…
superuser404notfound commentedon Jul 21, 2026
Closing the loop on the separate VOD growth flagged above: it became #174 and is fixed in 5.17.3.
For the record, my speculation above was wrong on the subsystem. It was neither IOSurface/VideoToolbox decode output nor CoreMedia sample-buffer backing. The growth was URLSession-internal transport buffering on the source fetch: the persistent reader applied backpressure by blocking the delegate callback, which has no flow-control contract, so on the TLS/H2 path the connection kept reading from the origin at line rate and the undelivered body accumulated without bound (malloc-backed, but transport-internal, which is why the Allocations view still missed it while
mallocMB/physFPclimbed). The thread-stack sweep in #174 is what pinned it, no vmmap needed. Full root cause and the fix are in that thread.Merge upstream/main (5.28.2) into fix/truehd-oom-backpressure