Skip to content

feat: slim new simulators before their first boot - #65

Merged
Interlap01 merged 4 commits into
MobAI-App:mainfrom
ovitrif:feat/preslim-before-first-boot
Nov 4, 2026
Merged

Interlap01 merged 4 commits into
MobAI-App:mainfrom
ovitrif:feat/preslim-before-first-boot

Conversation

@ovitrif

@ovitrif ovitrif commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

simslim watch slimmed a simulator only after it booted, so every new simulator's first boot started the full daemon set. Scripts and CI that create a fresh simulator per run never got past that first boot, and booting a few at once saturated the Mac.

This PR has watch write the profile's disable overrides into a shut-down simulator's launchd store, the same store simslim on uses, so its first boot already skips those daemons.

  • Seeding new simulators: watch follows the device-set directories with a kqueue watch and seeds each new simulator from its device.plist, in its own goroutine. It does not wait for simctl list, which on a loaded host takes longer than a script waits between simctl create and boot. A script that boots right after creating should run simslim on <udid> --preserve-boot-state in between.
  • On startup: watch now writes the profile into every shut-down simulator in the watched sets, not only the ones that boot while it runs.
  • Only adds disables: like the no-reboot slim at boot, it never re-enables a service. --except works as before.
  • Fallback kept: the no-reboot slim at boot still runs. It reads the result back and catches a boot that starts before the seed lands, as well as clones and older runtimes.

Results

First 90 s after boot, fresh simulator, iOS 26.5 runtime:

Host Stock first boot Seeded first boot
M5 Mac 471 processes, 780 CPU-s 117 processes, 149 CPU-s
M1 Mac, heavily loaded 306 processes, 273 CPU-s 135–141 processes, 108–121 CPU-s
  • Daemons skipped: launchd's log shows 135 of the profile's 136 services never started. com.apple.siri.context.service starts on demand, and the slim at boot stops it.
  • Examples: assetsd, medialibraryd, photoanalysisd, healthd, STExtractionService, UnityPoster, PosterBoard and searchd ran on stock first boots and not on seeded ones.
  • Boot time: on the M5, boot took 13.9 s against 15.8 s for stock.
  • Race: creating a simulator and booting it immediately still beat the slim at boot on both hosts, with the M1 at load 125–250.

Tests

make check passes. New cases in watch_test.go cover seeding a shut-down device before boot, retrying a failed seed, adding only disables, leaving other devices alone, finding a new device directory and reading its device.plist, forgetting deleted devices, and attaching to a set directory created later.

watch now writes the profile's disable overrides into a shut-down simulator's launchd store, so its next boot, its very first included, starts none of those daemons. It lists the device-set directories every 50ms and seeds a new simulator from its device.plist, without waiting for a simctl list, which on a loaded host takes longer than a script waits between create and boot. It only adds disables, like the no-reboot slim at boot, which stays as the read-back and the fallback for clones, older runtimes and a boot that starts before the seed lands.
@pawisoon

Copy link
Copy Markdown

Awesome! can we get it merged? @sunjinshuai

@Interlap01 Interlap01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a great addition, and the first-boot numbers are convincing. A few changes before merging:

  1. Replace the 50 ms directory poll with a kqueue watch (EVFILT_VNODE + NOTE_WRITE on each device-set folder, all in Go's standard syscall package, so the library stays dependency-free). The poll keeps waking up 20 times a second for as long as watch runs. kqueue costs nothing while idle and notices a new folder in under 1 ms. If a set folder doesn't exist yet (e.g. XCTestDevices before the first parallel-test run), try attaching to it again on each 3s scan.
  2. Handle each new folder in its own goroutine (counted in wg). Right now seedNew's 2s wait for device.plist blocks the loop that looks for new folders, so a batch of parallel-testing clones gets seeded one at a time.
  3. Remove deleted folders from known. Otherwise it grows by one entry per clone for the whole session.
  4. Drop the README advice to wait for /private/var/tmp/.../disabled.plist. It's an internal CoreSimulator path, and the script waits forever if watch isn't running, the runtime is older than iOS 18.5, or the profile adds nothing. For scripts, recommend simslim on <udid> --preserve-boot-state between simctl create and boot instead; that has no race.
  5. Call out the behaviour change in the README: on startup, watch now writes the slim profile into every shut-down simulator, not only the ones that boot while it runs.

Replace the 50ms directory poll with a kqueue NOTE_WRITE watch on each
device-set directory, re-attached each scan interval while a set directory
is missing. Seed each new device in its own goroutine, forget deleted
device directories and prune deleted UDIDs from seen and seeded.

README: recommend on --preserve-boot-state between simctl create and boot
instead of waiting for the store file, and call out that watch now slims
every shut-down simulator on startup.
@ovitrif

ovitrif commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@Interlap01 thanks for the review. All five are addressed in 8d26bc6.

  1. Replace the 50 ms directory poll with a kqueue watch

watchDeviceDirs (watch_dirs_darwin.go) registers EVFILT_VNODE with NOTE_WRITE on each device-set folder, using only syscall. It blocks in kevent while idle, and an EVFILT_USER trigger wakes it when the context is cancelled. A set folder that doesn't exist yet is attached again on each scan interval, and the devices it holds by then count as new. A set folder that gets deleted is detached and re-attached the same way. Other platforms get a no-op stub, so the library still builds and tests anywhere.

  1. Handle each new folder in its own goroutine (counted in wg)

Done. Each new folder's seedNew runs in its own goroutine, counted in wg, so a batch of clones is seeded in parallel.

  1. Remove deleted folders from known

Done. Each NOTE_WRITE relists that set folder and replaces its entries, so deleted folders drop out. seen and seeded had the same per-clone growth, so each scan now prunes the UDIDs that simctl list no longer returns.

  1. Drop the README advice to wait for /private/var/tmp/.../disabled.plist

Removed. The README now recommends simslim on <udid> --preserve-boot-state between simctl create and boot.

  1. Call out the behaviour change in the README

Added: on startup, watch writes the slim profile into every shut-down simulator in the watched sets, and simslim off <udid> brings one back to stock.

make check passes. The new tests cover a device created after the watch starts, a deleted device being forgotten, a set folder created later, and the pruning.

@Interlap01 Interlap01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thank you

@Interlap01
Interlap01 merged commit cfa980b into MobAI-App:main Nov 4, 2026
1 check 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