Skip to content

Shrink ORT arena per window and abort separation on memory warnings - #83

Merged
sanylax0 merged 1 commit into
mainfrom
claude/repo-review-improvements-yvk3t7-oom-arena-shrink
Jul 18, 2026
Merged

sanylax0 merged 1 commit into
mainfrom
claude/repo-review-improvements-yvk3t7-oom-arena-shrink

Conversation

@sanylax2

Copy link
Copy Markdown
Collaborator

What

The device still jetsams during stem separation even with prepacking disabled (#81). The remaining spike is inference itself: HT-Demucs' attention intermediates grow ONNX Runtime's CPU arena to a high-water mark that is never returned between windows — it sits on top of live playback, decode buffers, and the UI for the entire track.

How

Two independent levers:

  1. Per-run arena shrinkage — ORTRunOptions config memory.enable_memory_arena_shrinkage = cpu:0 on every window's run, so the arena's spike is returned to the OS after each 7.8 s window instead of held for the whole track. Re-growing the arena per window costs some CPU; separation is an offline cache-once job, so slower-but-alive wins (the same trade Fix launch jetsam + remove static onnxruntime embed #59 made choosing the CPU EP).
  2. Graceful abort on memory warnings — iOS warns before it kills. UIApplication.didReceiveMemoryWarningNotification (wired in RootView) now calls PreparationQueue.handleMemoryPressure(), which flags the streaming loop to bail before its next window (the existing error path deletes the partial stems) and drops the cached ORT session. The track keeps playing without stems and re-enters separation on a later ensureStems pass. The flag is cleared at the start of each fresh separation so a stale warning can't kill future attempts.

Testing

Not buildable in this environment. On device: play a fresh track and watch the Xcode memory gauge — RSS should now saw-tooth per window instead of ratcheting up, and if a warning still fires, the console will show the "aborted under memory pressure" stem log instead of a silent kill. If it still jetsams after this, the next diagnostic step is the JetsamEvent report (Settings → Privacy & Security → Analytics Data) to see the actual page counts — please share the header if so.

🤖 Generated with Claude Code

https://claude.ai/code/session_013TJoWkqg8bzkGdzxWhWjWP


Generated by Claude Code

Device still jetsams during stem separation with prepacking disabled:
the transformer's attention intermediates spike ONNX Runtime's CPU
arena to its high-water mark, which is never returned between windows
and sits on top of live playback for the whole track. Two levers:

- Per-run arena shrinkage (memory.enable_memory_arena_shrinkage) frees
  the spike after every 7.8 s window; re-growing costs some CPU, which
  an offline cache-once job can afford.
- iOS memory warnings now abort the in-flight separation (partial
  stems are deleted; the track plays without stems and retries on a
  later ensureStems pass) and drop the cached session — wired from
  RootView via PreparationQueue.handleMemoryPressure().
@sanylax0
sanylax0 merged commit cfb6d38 into main Jul 18, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants