Skip to content

perf(platform-ios): overlap XCTest agent build with simulator boot#171

Open
V3RON wants to merge 2 commits into
mainfrom
perf/ios-parallel-xctest-build
Open

perf(platform-ios): overlap XCTest agent build with simulator boot#171
V3RON wants to merge 2 commits into
mainfrom
perf/ios-parallel-xctest-build

Conversation

@V3RON

@V3RON V3RON commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What is this?

On iOS simulator runs with permissions enabled, Harness built the XCTest permission agent strictly after the simulator finished booting, even though the build phase never touches the simulator. This serialized two independent, often lengthy operations for no reason—most noticeably on a cold xcodebuild cache (e.g. right after an Xcode version bump).

How does it work?

In getAppleSimulatorPlatformInstance, the XCTest agent controller is now constructed as soon as the simulator's udid is known (before boot), and prepare() (the build-only phase, xcodebuild build-for-testing against generic/platform=iOS Simulator) is kicked off immediately without being awaited. The simulator boot/waitForBoot/install/harness-JS-override sequence then runs as before, unaffected by the build. Once that sequence finishes, the outstanding preparePromise is awaited first (so a build failure still surfaces and fails startup), followed by ensureStarted(), which internally re-calls prepare()—a no-op since it's idempotent—before launching the agent process against the now-booted device.

This is safe because:

  • prepare() only depends on the udid, which is already known before boot, and never touches the booted device (the run phase, test-without-building against id=<udid>, is untouched and still runs after boot).
  • prepare() is idempotent (if (prepared) return), so calling it early and letting ensureStarted() call it again is a no-op.
  • The build promise is given a .catch at creation to avoid an unhandled-rejection warning if boot fails first, while still being awaited inside the try block so the real error is surfaced and the existing finally cleanup (dispose agent, clear the harness JS override, shut down the simulator if Harness booted it) still runs correctly on any failure path.
  • When permissions is disabled, xctestAgent stays null and preparePromise is undefined, so behavior is byte-for-byte unchanged.

getApplePhysicalDevicePlatformInstance is untouched—physical device runs don't boot a simulator, so there's nothing to overlap.

Why is this useful?

The two operations are independent, so running them concurrently removes dead time from Harness startup on simulator runs with permission auto-acceptance enabled. The win is largest on cold build caches, such as right after an Xcode version bump, where the XCTest agent build can take a while and previously ran back-to-back with the simulator boot instead of alongside it.

The XCTest agent build (xcodebuild build-for-testing, destination
generic/platform=iOS Simulator) does not need a booted device, only the
later launch phase does. Kick off the build immediately after resolving
the simulator udid so it overlaps with bootSimulator/waitForBoot instead
of running strictly after it, cutting startup time on simulator runs
with permissions enabled, especially on a cold build cache.

prepare() is idempotent and ensureStarted() already calls it internally,
so calling it early and awaiting it again before ensureStarted() is safe.
The permissions-disabled path is unchanged (xctestAgent stays null).
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-native-harness Ready Ready Preview, Comment Jul 22, 2026 12:12pm

Request Review

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.

1 participant