Skip to content

Reduce simulator lifecycle polling overhead in multi-device workflows #703

@shaun0927

Description

@shaun0927

Tracked by #713.

Background

Parallel simulator automation is a core OpenSafari value. Repeated full simctl list devices -j polling during boot/shutdown can become expensive on machines with many runtimes or devices.

Objective

Make simulator lifecycle waits cheaper and more deterministic for parallel device workflows.

Scope

  • Use narrower simulator status commands where available.
  • Add short-lived device state caching during polling loops.
  • Share state lookups between manager and pool code.
  • Keep behavior compatible with supported Xcode versions.

Target files and paths

  • src/simulator/manager.ts
  • src/simulator/sim-pool.ts
  • src/simulator/pool.ts
  • src/simulator/simctl.ts
  • tests/unit/*simulator*.test.ts

Implementation steps

  1. Audit current boot/shutdown polling callers.
  2. Introduce a simulator state reader with a short TTL for repeated polling.
  3. Use simctl bootstatus <udid> -b for boot readiness when it is available.
  4. Keep fallback to current polling for unsupported environments.
  5. Add tests for cache hit, cache invalidation, and fallback paths.

Acceptance criteria

  • Boot wait does not repeatedly parse the full device list when a narrower command is available.
  • Shutdown wait uses a bounded polling strategy with clear timeout behavior.
  • Parallel pool operations share state reads during a polling tick.
  • Fallback behavior works when bootstatus is unavailable.

Verification

  • npm run lint -- --quiet
  • Targeted simulator manager/pool unit tests
  • Manual macOS smoke: boot and shutdown one simulator, then two simulators in parallel.

Dependencies / recommended order

Run after the proxy/WebKit speed issues or in parallel by a separate PR because it touches simulator lifecycle only.

Risks and cautions

  • Do not assume all Xcode versions support the same simctl commands.
  • Do not cache state across lifecycle mutations without invalidation.
  • Do not hide timeout errors.

Non-goals

  • Do not redesign device preset selection.
  • Do not change public tool names or parameters.
  • Do not optimize native input routing in this issue.

Ambiguity reducers

  • “Short TTL” means cache lifespan measured in a single polling interval, not long-term device inventory caching.
  • Fallback must be explicit and tested.
  • Lifecycle actions invalidate relevant cache entries.

Validity review

Proceed. This directly supports parallel multi-device automation and CI speed.

Implementation detail refinements

  • Wrap bootstatus use in a capability-detected helper.
  • Record the command path in debug logs without excessive noise.
  • Prefer dependency injection for Simctl in tests.

Verification checklist reinforcement

  • Boot path uses bootstatus or documented fallback.
  • Cache invalidates after boot/shutdown/delete.
  • Unit tests cover unavailable-command fallback.
  • Parallel boot test avoids duplicate full-list calls in mock assertions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    automation-roadmapOpenSafari automation roadmap work itemsperformancePerformance optimization

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions