Skip to content

perf(devices): probe platform inventories concurrently - #1524

Merged
thymikee merged 1 commit into
mainfrom
perf/parallel-device-inventory
Jul 31, 2026
Merged

perf(devices): probe platform inventories concurrently#1524
thymikee merged 1 commit into
mainfrom
perf/parallel-device-inventory

Conversation

@thymikee

Copy link
Copy Markdown
Member

Found while scoping #1522. The usbmux discovery idea was justified by resolve_target_device costing 6672 ms in the #1517 cabled capture — but breaking that number down showed usbmux was aiming at the wrong target.

Where the time actually went

Per-probe durations from that capture:

probe cost
vega device list 2833 ms
xctrace list devices 1814 ms
devicectl list devices 773 ms
simctl list devices 768 ms
emulator -list-avds 698 ms
adb devices -l 539 ms

They ran essentially back to back, because listLocalDeviceInventory awaited each platform inside a for loop. An unfiltered lookup therefore cost the sum of every installed toolchain — and for an open targeting an iPhone by name, most of that was spent enumerating platforms the request could never resolve to. The single largest contributor was Vega, which has nothing to do with the request.

usbmuxd discovery would only have shaved the two Apple probes. Removing the serialization is worth more, and it helps Android and Vega users equally.

Change

Probe the platforms concurrently and concatenate the results in selector order. Ordering is load-bearing and preserved: the Linux local device must stay last so it does not displace connected Android/Apple devices in implicit auto-selection, and Promise.all keeps input order.

Measured

Alternating A/B on one host against the same cabled iPhone, rebuilding between arms, three runs each:

arm run 1 run 2 run 3
sequential 4065 ms 4015 ms 3912 ms
concurrent 2359 ms 2365 ms 2295 ms

~1.7x, about 1.65 s off every cold device resolution. (Absolute numbers are below the original 6.7 s because that capture was taken on a busier host; the ratio is what alternating runs control for.)

Behaviour preserved

  • Result order is unchanged, asserted explicitly.
  • A failing probe still cannot take down the others — each is caught individually.
  • A probe returning a non-array still contributes nothing. That used to happen implicitly, because spreading a non-array threw into the per-platform catch; .flat() would instead have kept an undefined in the list. A pre-existing test caught this, and it is now explicit.

Testing

  • concurrency: each stubbed probe blocks until all four have started, so the test deadlocks unless they genuinely overlap. Verified revert-sensitive — the sequential loop makes it time out.
  • ordering: asserts android, apple, vega, linux in the result.
  • isolation: two probes reject, and the devices found by the other two still come back.

pnpm check:affected --run passes.

An inventory lookup with no platform filter awaited each platform's toolchain
in turn, so it cost their sum. Opening a physical iPhone by name spent 6.7s in
resolve_target_device on a host with the Apple, Android and Vega toolchains
installed, most of it enumerating platforms the request could not target
(vega device list alone was 2.8s of it).

The probes are independent, so run them concurrently and concatenate in
selector order — the Linux local device still lands last, where it must be so
it does not displace connected Android/Apple devices in implicit selection.

Alternating A/B on one host against a cabled iPhone, three runs each:
sequential 4065/4015/3912ms, concurrent 2359/2365/2295ms.

A platform answering with a non-array still contributes nothing: spreading it
used to throw into the per-platform catch, and that is now explicit.
@github-actions

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
JS raw 1.91 MB 1.91 MB +52 B
JS gzip 613.3 kB 613.3 kB +23 B
npm tarball 731.0 kB 731.0 kB +36 B
npm unpacked 2.56 MB 2.56 MB +52 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 20.9 ms 22.0 ms +1.1 ms
CLI --help 44.9 ms 44.5 ms -0.4 ms

Top changed chunks: no changes in the largest emitted chunks.

@thymikee
thymikee merged commit ac286d2 into main Jul 31, 2026
30 checks passed
@thymikee
thymikee deleted the perf/parallel-device-inventory branch July 31, 2026 11:49
@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-31 11:49 UTC

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