Skip to content

perf(wda): stop a simulator's app with simctl before WebDriverAgent's terminate - #271

Closed
luka-vladika-happening-xyz wants to merge 1 commit into
devicelab-dev:mainfrom
luka-vladika-happening-xyz:fix/wda-simctl-stop-on-simulator
Closed

luka-vladika-happening-xyz wants to merge 1 commit into
devicelab-dev:mainfrom
luka-vladika-happening-xyz:fix/wda-simctl-stop-on-simulator

Conversation

@luka-vladika-happening-xyz

@luka-vladika-happening-xyz luka-vladika-happening-xyz commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

On a simulator the WDA driver stops an app through WebDriverAgent (/wda/apps/terminate), which is XCTest's terminate: on an iPhone 18 Pro simulator (iOS 27.2) it took 1.1-2.1 s for our app, where xcrun simctl terminate takes 0.19 s. A flow pays it at every launchApp of a running app (a clearState launch stops it before the reinstall, a plain one before relaunching), and at stopApp and killApp. DeviceLab's iOS driver and Maestro stop a simulator's app with simctl.

The change: terminateApp, when there is a session and the device is a simulator, runs simctl terminate first, then sends WebDriverAgent's terminate as before. The second call is still needed: when the session's app is stopped behind WebDriverAgent's back, its next request fails with "The application under test … is not running, possibly crashed". After simctl it returns in 20-30 ms (the app is not running) and clears that state. launchApp's stop before a launch goes through terminateApp too. A real device is unchanged (WebDriverAgent only), as is a simulator without a session (simctl only, as before). simctl's own error (the app was not running) is logged at debug level and ignored.

Measured on that simulator, three rounds each: simctl then WebDriverAgent 0.18 + 0.02 s against WebDriverAgent alone 1.1-2.1 s, the app state "not running" after and the next request answering normally; five flows that start with launchApp: clearState in one runner process: each 0.3-0.8 s faster, 71.6 s against 74.5 s for the five (medians), every flow passing with both.

Tests: TestTerminateAppOnASimulatorUsesSimctlFirst (with the package's execCommand seam: a simulator runs simctl, then WebDriverAgent's terminate; a device only the latter; fails without the change). go test -race ./pkg/driver/wda/ ./pkg/executor/ ./pkg/flow/ passes; golangci-lint v2.13.2: 0 issues.

… terminate

WebDriverAgent's terminate is XCTest's, which took 1.1-2.1 s to stop the
app on a simulator; `simctl terminate` takes 0.2 s. A flow pays it at every
launchApp of a running app (clearState's launch stops it before the
reinstall) and at stopApp and killApp.

With a session on a simulator, the driver now stops the app with simctl,
then sends WebDriverAgent's terminate, which returns at once for an app that
is not running and keeps the session's bookkeeping: an app of the session
stopped behind its back reads as crashed at the next request. launchApp's
stop before a launch goes through the same path. A real device stops it
through WebDriverAgent only.
@codecov

codecov Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/driver/wda/commands.go 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@omnarayan

Copy link
Copy Markdown
Contributor

Thanks, Luka. We measured this on our simulator before merging, and it made terminating slower:

  • 10 terminates through WDA took over 3 s each;
  • one hung for 60 s;
  • RNTester's suite ran about 15% longer overall.

simctl terminate itself is fine, but going through it first puts its cost on every stop. Would you rework it so the simctl path runs only when WDA's terminate fails or times out, with a short limit of its own? If that doesn't fit what you were fixing, tell me the case you hit and we'll look at it from there.

@luka-vladika-happening-xyz

Copy link
Copy Markdown
Contributor Author

Thanks, you're right, and I could reproduce it. With the runner starting its own WebDriverAgent (xcodebuild, Xcode 27.2, an iOS 27.2 simulator), WebDriverAgent's terminate after simctl's took 8-12 s in 13 of 25 stops of our app with this change, and in none of 20 without it; a flow of five launchApp/stopApp pairs ran 50-60 s against 29 s. My numbers came from a WebDriverAgent started with simctl launch, where this doesn't happen. A fallback for when WebDriverAgent's terminate fails wouldn't help the case I was after (it doesn't fail, it takes about a second), so I'm closing this one.

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