Skip to content

feat: add @metamask/mwp-connect-bench private benchmark harness - #341

Open
adonesky1 wants to merge 7 commits into
mainfrom
ad/mwp-connect-bench
Open

feat: add @metamask/mwp-connect-bench private benchmark harness#341
adonesky1 wants to merge 7 commits into
mainfrom
ad/mwp-connect-bench

Conversation

@adonesky1

Copy link
Copy Markdown
Contributor

Explanation

Adds playground/mwp-connect-bench — a private, unpublished package for measuring MetaMask Connect (MWP) deeplink connection latency against a MetaMask Mobile dev build in the iOS simulator, and for verifying connection-flow changes don't regress session resume.

Why: we needed a repeatable rig to A/B MetaMask/metamask-mobile#32475 (defer session resume/reconnect while a new connect is in flight, WAPI-1566), and the pieces are reusable for any MWP connect-latency experiment (WAPI-1564 investigation).

What's inside:

  • patches/mwp-perf-instrumentation.patch — NOT-for-merge patch adding [MWPPerf] timing logs to metamask-mobile's Connection service (create / connect-handshake / resume spans). Applied locally to the build under test.
  • seed-sessions.mjs — persists N synthetic MWP sessions to create cold-start resume load. Works because trusted-mode handshakes require no dapp acknowledgement: a valid connect deeplink without initialMessage (QR-style) does a real relay handshake and persists a session with no approval UI. Payloads pass the wallet's isConnectionRequest() validation, including real compressed-secp256k1 peer keys (via this package's own eciesjs dep, pinned to the version already in the repo).
  • run-trial.mjs — one cold-start measurement trial (force-kill app → fresh connect deeplink via the mmdl simulator CLI).
  • analyze.mjs — parses tee'd Metro logs; reports median/p75 handshake durations, resume failures (regression check), and resume-during-connect counts (contention indicator).

The README documents the full A/B protocol (single native build, JS-only arm swap, ABBA trial blocks, network throttling, median-based comparison) and trial hygiene (session cap, simulator persistence, cleanup).

Constraints/CI: playground packages are excluded from the publish/constraints checks (yarn.config.cjs), and yarn constraints passes. Lockfile updated for the new workspace.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate (N/A — measurement harness, no runtime code shipped)
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed (private package CHANGELOG added)
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes (N/A — no consumers)

Private, unpublished playground package for measuring MetaMask Connect
(MWP) deeplink connection latency against a MetaMask Mobile dev build in
the iOS simulator. Includes: a NOT-FOR-MERGE instrumentation patch for
metamask-mobile's Connection service ([MWPPerf] timing logs), a session
seeder that persists synthetic trusted-mode sessions via real relay
handshakes (no dapp required, no approval UI), a cold-start trial runner,
and a log analyzer that reports median/p75 handshake durations plus
resume-regression and contention indicators.

Built to A/B metamask-mobile#32475 (defer session resume/reconnect while
a new connect is in flight, WAPI-1566); reusable for any MWP
connect-latency experiment (WAPI-1564).
@adonesky1
adonesky1 requested a review from a team as a code owner July 24, 2026 21:02
- Add create_session_received marker to the instrumentation (when the
  wallet_createSession request reaches the wallet) and an "approval gate"
  metric (create_session_received - connect_start) to the analyzer, so the
  approval path can be measured, not just the handshake.
- Add --with-request trial mode: embeds an inline wallet_createSession
  (direct-deeplink flow) so approval-path trials are possible. Each such
  trial pops a real approval; reject between trials.
- Add a dedicated instrumentation patch variant for metamask-mobile#32470
  (eager approval), whose refactored Connection service the base patch
  cannot target. Base patch verified against main, #32475, and #32473;
  variant verified against #32470.
- Add a per-PR measurement guide (patch/trial-mode/metric/expected result
  for #32475, #32470, #32473) to the README.
…marked

Release builds strip console.* via transform-remove-console and run without
Metro, so the instrumentation now logs through a bound console.warn alias and
appends JSON lines to <Documents>/mwp-perf.log (both patch variants). README
documents the Release-build workflow (cold-start fidelity, log collection,
arm-swap rebuild caveat).
Remove shebangs, replace process.exit with throw, rename short/denylisted
identifiers, add curly braces and JSDoc description, fix import order.
The ./lib.mjs extension imports keep a targeted inline disable — plain
Node ESM requires the extension at runtime.
Deliver deeplinks with plain 'xcrun simctl' (terminate + openurl) so the
harness has no dependency on private local tooling; simulator and bundle id
are overridable via BENCH_SIM_DEVICE / BENCH_BUNDLE_ID. Add AGENTS.md with
the dev-build and Release-build playbooks plus the pitfalls learned running
the first A/B (dev-launcher deeplink swallowing, console stripping, rebuild
after arm swap, session cap, trial spacing, throttle verification).
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