# iOS Simulator RAM Calculator

`xcloom` detects unified memory via `sysctl hw.memsize`, applies dual-tier pre-boot `disabled.plist` pruning across `19` daemon categories (`147` entries in Safe Default, up to `160` with App-Aware `--for`, keeping `24` critical daemons always protected), and caps active simulator slots using macOS `ri_phys_footprint` budgets so parallel coding agents do not trigger swap thrashing.

## Hardware-Adaptive Slot Reference

Slot accounting uses `1 stock simulator = 3 slim slot units`. On `<= 16 GB` hosts (`cap=2`), the first stock simulator is admitted when the pool is empty.

| Mac Unified Memory (`sysctl hw.memsize`) | XCLoom Slim Simulator Slots | Stock Simulator Equivalent | Built-in Pre-Boot Pruning |
| --- | --- | --- | --- |
| `<= 16 GB` | `2` slim slots | `1` stock (`cap=2`, first stock admitted when pool is empty) | `147` default / `160` app-aware (`--for`) entries across `19` categories (`24` always-protected daemons) |
| `24 GB` (`17–24 GB`) | `3` slim slots | `1` stock | `147` default / `160` app-aware (`--for`) entries across `19` categories (`24` always-protected daemons) |
| `32–36 GB` (`25–36 GB`) | `4` slim slots | `1` stock | `147` default / `160` app-aware (`--for`) entries across `19` categories (`24` always-protected daemons) |
| `48 GB` (`37–48 GB`) | `6` slim slots | `2` stock | `147` default / `160` app-aware (`--for`) entries across `19` categories (`24` always-protected daemons) |
| `64 GB` (`49–64 GB`) | `8` slim slots | `2` stock | `147` default / `160` app-aware (`--for`) entries across `19` categories (`24` always-protected daemons) |
| `96 GB` (`65–96 GB`) | `10` slim slots | `3` stock | `147` default / `160` app-aware (`--for`) entries across `19` categories (`24` always-protected daemons) |
| `128 GB+` (`>= 97 GB`, incl. 192 GB / 512 GB) | `12` slim slots | `4` stock | `147` default / `160` app-aware (`--for`) entries across `19` categories (`24` always-protected daemons) |

Why `1 stock simulator = 3 slim slot units`, why `512 GB` caps at `12` slots, and why `8–16 GB` share `2` slots: `1 stock = 3 slim` is a pool scheduling weight for CPU/I/O boot contention (stock boots ~200 daemons vs 85 in App-Aware) plus App-Aware's ~2.4x RAM cut (`1.70 -> 0.72 GiB`), not a 3x RAM savings guarantee under Safe Default (`-20.3%`, `1.88 -> 1.50 GiB`). Default concurrency caps at `12` slim slots even on `512 GB` Macs because `CoreSimulatorService` IPC and disk/CPU contention saturate well before 512 GB of RAM fills up (override via CLI flags if needed). In code, `<= 16 GB` (including 8 GB Macs) uses the floor tier (`cap=2` slim slots, or `1` stock when empty); if you run Xcode or an IDE alongside agents on 8 GB, pass `--max-sims 1` to leave memory headroom.

## Footprint Calibration Note

Standard `ps` RSS sums private memory together with shared dynamic library pages mapped into every `launchd_sim` child process, which double-counts the iOS runtime dyld shared cache and inflates reported RAM. XCLoom measures simulator memory strictly through macOS `proc_pid_rusage` (`ri_phys_footprint`), matching Activity Monitor's physical footprint metric.

In this interactive calculator, the per-simulator baseline fields bind directly to two separate alternating slim/stock A/B pairs measured on `2026-11-22` on Mac15,14 (`iPhone Air`, `iOS 27.3`, `12s` settle; full methodology on `/benchmarks/`). Because iOS background daemon memory varies ~10% between boots, each tier compares strictly against its own paired stock baseline (`1.88 GiB` for Safe Default; `1.70 GiB` for App-Aware), which is why switching tiers shifts the paired stock baseline readout:

- Safe Default (`xcloom sim boot`, slim by default while `--stock` opts out; `147` disabled entries across `19` categories, keeps `widgets`/`store`/`photos` enabled): physical footprint `1.88 GiB` -> `1.50 GiB` (`-20.3%`, `-0.38 GiB`), live `launchd_sim` processes `213` -> `140` (`-34.3%`), cold boot wall `2.37s` stock -> `2.94s` slim (`+0.57s` from pre-boot `disabled.plist` backup/merge and `launchd_sim` startup adjustment).
- App-Aware Auto-Slim (`--for MinimalApp.app`, auto-enabled in `xcloom run --smoke`, `xcloom matrix`, and `xcloom test` via `2 ms` warm `.app` / `15 ms` repo static analysis of entitlements, `Info.plist`, `.appex`, and `LC_LOAD_DYLIB`; disables unused `widgets`/`store`/`photos` up to `160` entries): physical footprint `1.70 GiB` -> `0.72 GiB` (`-57.3%`; unrounded `1.695 -> 0.724 GiB`, `-0.97 GiB`), live `launchd_sim` processes `190` -> `85` (`-55.3%`), cold boot wall `2.49s` stock -> `3.02s` slim (`+0.53s` from pre-boot `disabled.plist` backup/merge and `launchd_sim` adjustment).
- `24` critical daemons always stay protected: `com.apple.assistantd` prevents Spotlight memory leaks inside the simulator, `com.apple.gamed` prevents XCUITest `DTServiceHub` launch stalls, and `com.apple.coredevice.dtuhidd` preserves CoreSimulator host bridging, HID control, and `iPhone Duo` support. Passing `--stock` restores the exact original `disabled.plist` bytes.

Run `xcloom sim status` locally for a read-only readout of every currently booted simulator and its `ri_phys_footprint` on your own machine.

## Frequently Asked Questions

### Why `ri_phys_footprint` instead of RSS?

RSS counts shared dyld and framework pages once per child process inside `launchd_sim`, exaggerating both stock consumption and claimed savings. Reading `ri_phys_footprint` via `proc_pid_rusage` reflects actual physical memory pressure and compressed pages owned by the simulator tree.

### Why cap concurrent cold boots at 2 slim or 1 stock?

Simulator cold boot spikes CPU, disk I/O, and `CoreSimulator` IPC simultaneously. Capping concurrent cold boots at `2 concurrent slim boots (or 1 stock boot)` with opt-in queuing via `--wait-secs` prevents boot storms when four or eight coding agents request simulators at the same second, keeping total time-to-ready lower than parallel contention.

### Does XCLoom touch Xcode's simulators?

No. Pool leases (`xcloom sim lease`, used automatically by `run`, `matrix`, and `test`) track every XCLoom-allocated simulator via owner-PID + TTL leases with automatic background reaping on process exit. Manual `xcloom sim boot` instances stay running until you call `xcloom sim shutdown`. Simulators launched by Xcode, Simulator.app, or another project remain untouched.
