Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(bench): time startup, idle CPU and quit against VS Code

rokartur88a4cfb9baa9
diff --git a/port/ledger.md b/port/ledger.md
index 08058820f20..b2016ee9e2d 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -155,7 +155,7 @@ Status: `open`, `in progress`, `waiting on Artur`, `later` (postponed), `done`,
| M21 uplift | extension/markdown-language-features | later | M17, 99 lines: the new `markdown.editor.initialMode` (read or edit, default read) is read by the extension itself; `@vscode/markdown-editor` bump. | settings-check lists it; `FIXTURE=markdown-tests port/tools/webview-check` |
| M21 uplift | workbench/contrib/extensions | later | M18, about 129 lines (`extensions.contribution`, `extensionsCopyActions`, `extensionsActions`): Copy Link's `when` becomes `extensionHasGalleryLink` (set when the extension has a url), replacing `galleryHasExtensionLink`. The Manage gear in the extension editor hides when the ExtensionContext menu has nothing for the extension. | ui-pair of the extension editor header and context menu |
| M21 uplift | platform/update | later | M19, 11 lines (`update.config.contribution`): `update.enableEarlyStaging` (macOS, default false, experimental) is registered by the settings dump and has no effect on the port's GitHub-release updater. | settings-check |
-| Later | Bun host size | later | Dropped from 57 to 41 MiB between milestones 1 and 2, not investigated (`port/results/benchmark.md`). | |
+| Later | Bun host size | later | Dropped from 57 to 41 MiB between milestones 1 and 2, not investigated (`port/results/benchmark.md` before the README benchmark, in git history). | |
| Later | Wu memory | later | Measured 99 MiB once and 154 to 156 MiB later, cause not investigated. | |
| Later | Bun native-watchdog | later | Bun runs without `@vscode/native-watchdog` (oven-sh/bun#18546): a host with a stuck event loop is not killed; recheck on each Bun upgrade. | |
| Later | files pass leftovers | later | No TypeScript suggest list after typing `x` in the ui-pair run (unchecked); Explorer not paired in the light and high contrast themes. | |
@@ -758,7 +758,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| gallery/open-vsx | cross-cutting check | M18 | verified | | exthost/src/gallery.rs: query, latest-version resource, version choice, download with signature check; cargo test -p exthost gallery (upstream extensionGalleryService.test.ts sorting and filterLatestExtensionVersionsForTargetPlatform cases, Open VSX resource fixture); `workbench.extensions.installExtension redhat.vscode-yaml` downloads 2.0.0 from open-vsx.org, verifies it and activates without restart, not-found errors as upstream: PORT_GALLERY=1 port/tools/extensions-check |
| port/settings-import | port feature | M10 | verified | | app/src/settings_import.rs, workbench/settings_import.rs: cargo test -p app settings_import installed_extensions_bring extensions_open_vsx_lacks_are_copied_from_the_source accepting_the_contents_pick_imports_every_part imported_extensions_ask_for_publisher_trust_once installed_extensions_bring_the_themes_the_settings_name an_empty_profile_takes_keybindings_json_with_its_comments reads_the_disabled_extensions on port/fixtures/settings-import; release GUI on the host lane: one import each from VS Code, Cursor and VSCodium fixtures under a scratch HOME. AI, sign-in, telemetry, remote and the editors' own settings and extensions are left out |
| look/screenshot-diff | cross-cutting check | | verified | | port/tools/pixel-check: CDP reference capture and Metal readback in 3 themes, pixeldiff reference vs itself 0 different; baseline in port/results/pixels.md |
-| perf/memory-benchmark | cross-cutting check | | verified | | port/tools/bench (Wu method), 3 runs on Studio; port/results/benchmark.md: exthost Bun 57 MiB, Node 98 MiB, reference 151 MiB |
+| perf/memory-benchmark | cross-cutting check | | verified | | port/tools/bench, median of 5 on the Studio, the VS Code 1.147.0 checkout open; port/results/benchmark.md: 218 MB in all, extension host 74 MB, VS Code 1.147.0 release 975 MB and 195 MB |
Unmerged paths: port/ledger.md. Read the resolving-merge-conflicts skill and follow it to the end.
\ No newline at end of file
diff --git a/port/notes.md b/port/notes.md
index b930cee3878..4f837173403 100644
--- a/port/notes.md
+++ b/port/notes.md
@@ -943,7 +943,7 @@ What to do (milestone 21, in order):
## Benchmarks
-- `port/tools/bench`: Wu's `script/memory-benchmark` method generalized to N apps (`APPS="name=cmd;..."`), plus an extension host line per app.
+- `port/tools/bench`: started as Wu's `script/memory-benchmark` method generalized to N apps (`APPS="name=cmd;..."`); now also window, ready, CPU, idle CPU and quit times with a folder open, for the README's table (method and numbers: port/results/benchmark.md). A fresh VS Code 1.147.0 profile opens a Copilot sign-in dialog that keeps the renderer and GPU process at about 65% of a core for minutes, and an untrusted folder runs without git: the benchmark sets `chat.disableAIFeatures` and passes `--disable-workspace-trust` to both apps.
- Wu's `.cargo/config.toml` links with Homebrew lld on aarch64-apple-darwin; the Studio has no lld, so Wu is built with `RUSTFLAGS="-C symbol-mangling-version=v0 --cfg tokio_unstable"` (same flags, Apple ld). Env `CARGO_TARGET_*_RUSTFLAGS` does not work for this: cargo appends it to the config array.
- Scroll frame costs (branch port-fix-settings-scroll): `settings_scroll_frame_time` (ignored test, `cargo test --release -p app -- --ignored settings_scroll_frame_time --nocapture`) scrolls the whole settings tree (1810 rows) in a headless 1440x900 workbench with gpui's NoopTextSystem, 600 frames of a 30px trackpad delta. Before: median 37.1 ms, p95 51.2 ms; `sample` put about 90% of the frame in `wordify_key` compiling 14 regexes per call, twice per visible row, and a third of the rest in `trim_category_for_group` compiling its group id patterns. With the regexes compiled once: median 3.3 ms, p95 3.7 ms. With the `config.*` context keys kept by `Configuration` until a layer changes (they were flattened again on every `key_context` call): median 1.7 ms, p95 2.1 ms (3 runs). The real app (Settings, search "editor", 572 rows; scratch CGEvent probe at 120 Hz on the Studio lane, main thread sampled): `Window::draw` held the main thread 93 to 97% of the time before, 56% after with the same input; what is left is the whole Workbench rendering on each frame (the layout row's gap). CoreText needs the main thread, which libtest never gives, so the headless check cannot use real text shaping.
- Scroll frame costs, every surface (branch port-fix-settings-scroll): `workbench/scroll_frame_time.rs` holds one ignored test per surface (`cargo test --release -p app -- --ignored scroll_frame_time --nocapture --test-threads=1`) on one fixture: a folder of 801 files with a 20000-line `large.ts` open, every built-in extension installed and running, 1440x900, gate median and p95 under 8 ms. Median / p95 ms for Explorer, Editor, Extensions @builtin and Settings (now with a folder open, so not comparable to the paragraph above): at abfb67458da 194.0 / 281.5, 236.2 / 252.2, 4.3 / 11.0, 190.8 / 228.0; with the Explorer drawing only the rows in view (taffy laid out all 801 rows) 35.8 / 41.0, 84.5 / 89.5, 4.2 / 4.5, 37.5 / 54.4; with `FileTree` reading a folder again only when its mtime changes (`rows()` listed and stat-ed every expanded folder, several times per frame through `key_context`) and glob patterns parsed once as glob.ts `CACHE` does (`resource_editors` compiled a regex per custom editor selector per `key_context` call) 13.3 / 39.2, 22.8 / 54.0, 4.3 / 5.5, 14.6 / 16.1. The Studio is shared, so runs vary by about 30%. What is left, from `sample`: in the Explorer half the frame is taffy laying out the whole workbench tree, where a nested flex item is measured twice per level; in the Editor render is 60% of the frame, of which the minimap 20% (`minimap_runs` resolves each token's theme style on every frame, where vscode-textmate keeps it in the token's metadata) and `key_context` 16% (built in full by the menubar, the timeline toolbar three times, the editor title actions, the outline pane and the floating menu). The Extensions badge the layout gap names does not show in a sample of the harness. Cached part views (`AnyView::cached`) would skip render and layout of the parts a scroll does not touch, but in the vendored gpui a notify of a rendered entity invalidates that entity's view only and fires no observers, so a part view drawn from the Workbench's state would not redraw when that state changes: this needs the parts' state in their own entities or a gpui change.
diff --git a/port/results/benchmark.md b/port/results/benchmark.md
index 398b6d0be90..c4a599656e8 100644
--- a/port/results/benchmark.md
+++ b/port/results/benchmark.md
@@ -1,25 +1,50 @@
-# Memory benchmark
+# Benchmark
-Method: `port/tools/bench` (Wu's `script/memory-benchmark`): fresh profile per run, 20 s settle, `footprint` summed over the process tree, median of 3. Mac Studio, macOS 27.2.1. Idle, no folder open. Copilot Chat excluded everywhere (removed by decision, see `port/notes.md`; the port's scanner now skips it, `scan.rs` `REMOVED_BUILTINS`).
+VSRustium against VS Code 1.147.0, both packaged release builds, opening the VS Code 1.147.0 checkout (21462 files, a git repository with its `node_modules`), measured from outside with `port/tools/bench`. Median of 5 runs after one warm-up run per app, runs alternating between the apps.
-| app | total MiB | extension host MiB | samples (KiB) |
-|---|---|---|---|
-| port, Bun host | 109.0 | 41.0 | 111616 111616 110592 |
-| port, Node host (control) | 153.0 | 85.0 | 156672 157696 156672 |
-| VS Code 1.147.0 reference (dev build) | 1978.2 | 151.0 | 2050241 2003153 2025665 |
-| Wu a3ced28 (release) | 156.0 | 0 (no extension host) | 159744 158720 161792 |
+| | VSRustium | VS Code 1.147.0 |
+|---|---|---|
+| Window with the folder | 0.79 s | 0.99 s |
+| Ready (CPU settled) | 2.47 s | 12.10 s |
+| CPU time until ready | 2.52 s | 10.07 s |
+| Memory (footprint, all processes) | 218 MB | 975 MB |
+| of which the extension host | 74 MB | 195 MB |
+| Idle CPU, 10 s after ready | 1.9 % of a core | 0.2 % of a core |
+| Quit | 0.14 s | 0.23 s |
-Extension host overhead, Bun against Node: -44 MiB (41 vs 85). Port rows rerun with the empty workbench drawn (milestone 2); the other rows are from milestone 1.
+Setup:
+
+- Machine: Mac Studio, Apple M1 Max (10 cores), 32 GB, macOS 27.2.1. The Studio is shared with other build and test jobs (load average 28 to 36 during the runs), so single runs vary; the medians are steadier.
+- VSRustium: `port/tools/package-app` of `vsrustium/main` at 161bc73f69f (a release build, ad-hoc signed, the reference's built-in extensions).
+- VS Code: the official 1.147.0 darwin-arm64 build from `update.code.visualstudio.com`, started with `--disable-extension GitHub.copilot-chat`: the port leaves Copilot Chat out by decision (`port/notes.md`), so both run the same built-in extensions.
+- Both: default settings except `"chat.disableAIFeatures": true` (without it VS Code opens its Copilot sign-in dialog on every start of a fresh profile and keeps a core busy drawing it), `--disable-workspace-trust` (otherwise both open the folder in Restricted Mode, without git and most extensions), an empty extensions folder, and one user data folder per app for all its runs, so caches are warm after the warm-up.
+
+Method (`port/tools/bench`, header): window is launch to the first on-screen window of the launched process; ready is launch to the start of the first 2 s after the window in which the process tree used under 10% of a core in each 0.5 s; CPU time is the tree's at ready, without processes that exited before; idle CPU is the tree's over the 10 s after ready; memory is `footprint` summed over the tree after that; quit is the quit Apple event until every process of the tree is gone.
Read with care:
-- The port draws the empty workbench (no folder, no editor). Against milestone 1's status window the shell grew from 52 to 68 MiB and the Bun host dropped from 57 to 41 MiB, so the total stayed at 109 MiB; the host drop was not investigated.
-- The reference is an unbundled dev build (`VSCODE_DEV=1`), heavier than a packaged release. A packaged reference build is still to measure.
-- Wu measured 99 MiB in one earlier full run and 154 to 156 MiB in two later ones; cause not investigated.
-- With Copilot Chat loaded, the port's host grows to 197 MiB (Bun) and 735 MiB (Node), because its activation never completes against the stub main thread. The reference host stays at 150 MiB with or without it.
-Commands:
+- VS Code's ready is bimodal: in 2 of 5 runs a 2 s pause at about 5 s passed as settled, and those runs then used 20% of a core in the idle window; in the other 3 the tree settled at about 12 s and idled at 0.2%. The median is one of the latter.
+- VSRustium idles at 1.9% of a core in the 10 s after ready, VS Code at 0.2%: VS Code wins this row. Not investigated.
+- VSRustium's run 5 (window 2.28 s, ready 8.18 s) and VS Code's quit in run 5 (22.3 s) are outliers that the shared Studio's load may explain; they stay in the samples.
+
+Samples (s, %, MB), in run order:
+
+| metric | VSRustium | VS Code 1.147.0 |
+|---|---|---|
+| window | 0.98 0.72 0.75 0.79 2.28 | 0.95 0.96 1.00 1.01 0.99 |
+| ready | 3.19 2.40 2.43 2.47 8.18 | 4.84 12.10 5.04 12.26 12.80 |
+| CPU until ready | 2.95 2.57 2.52 2.51 2.38 | 7.70 10.07 7.97 10.19 10.70 |
+| idle CPU | 1.9 1.7 1.9 2.0 1.0 | 19.6 0.2 20.5 0.2 0.2 |
+| memory | 218 217 219 219 217 | 975 874 925 986 984 |
+| extension host | 73 74 75 74 73 | 196 197 193 195 195 |
+| quit | 0.13 0.13 0.16 0.15 0.14 | 0.23 0.20 0.23 1.10 22.30 |
+
+To rerun, on the Studio after a release build and `port/tools/package-app`, with the VS Code build unpacked in `/tmp/vscode`:
```
-R=$HOME/Developer/vscode-ref; N=<extensions dir without copilot>
-APPS="wu=$HOME/Developer/wu/target/release/wu;vscode=env VSCODE_DEV=1 NODE_ENV=development \"$R/.build/electron/Code - OSS.app/Contents/MacOS/Code - OSS\" $R --disable-extension GitHub.copilot-chat;port-bun=env VSCODE_GPUI_EXTENSIONS=$N native/target/release/code-gpui;port-node=env VSCODE_GPUI_EXTENSIONS=$N native/target/release/code-gpui --node" port/tools/bench
+FOLDER=$HOME/Developer/vscode-ref SETTINGS='{"chat.disableAIFeatures": true}' \
+APPS='vsrustium=native/target/VSRustium.app/Contents/MacOS/vsrustium;vscode="/tmp/vscode/Visual Studio Code.app/Contents/MacOS/Code" --disable-extension GitHub.copilot-chat' \
+port/tools/bench
```
+
+Earlier memory-only numbers (milestones 1 and 2: an idle empty window, a dev build of the reference) are in this file's git history.
diff --git a/port/tools/bench b/port/tools/bench
index c27d4d3cef5..41e2c0720e8 100755
--- a/port/tools/bench
+++ b/port/tools/bench
@@ -1,16 +1,34 @@
#!/usr/bin/env bash
-# Memory benchmark, same method as Wu's script/memory-benchmark (a3ced28): fresh throwaway user data dir,
-# settle, sum footprint(1) over the process tree, quit; runs alternate between apps; median per app.
-# Prints one TSV row per app plus one row per extension host process ("<app> exthost").
+# Startup, memory and quit benchmark of whole apps, measured from outside the same way for each (port/results/benchmark.md).
+# Per app: one user data dir and one empty extensions dir for all its runs, a first warm-up run not counted, then RUNS
+# runs; runs alternate between apps. A run launches the command with the folder, then measures:
+# window: launch to the first on-screen window of the launched process (port/tools/bench-window.swift)
+# ready: launch to the start of the first 2 s, after the window, in which the process tree used under 10% of a core in
+# each 0.5 s
+# cpu: CPU time of the process tree at ready (processes that exited before are not counted)
+# idle: CPU of the tree over IDLE_SECONDS after ready, % of a core
+# memory: footprint(1) summed over the tree after that, and the part of it in extension host processes
+# quit: the quit Apple event to the launched process until every process of the tree is gone
+# Prints one TSV row per app and metric: the median and the samples.
#
-# APPS="name1=command1;name2=command2" port/tools/bench
-# Each command gets --user-data-dir <dir> appended. RUNS and SETTLE_SECONDS override the defaults.
+# APPS="name1=command1;name2=command2" FOLDER=<dir> port/tools/bench
+# Each command gets --disable-workspace-trust --user-data-dir <dir> --extensions-dir <dir> <FOLDER> appended; the
+# command must exec the app's binary (the process that owns its windows). SETTINGS (a JSON object) becomes every
+# app's user settings.json. RUNS (5) and IDLE_SECONDS (10) override the defaults.
set -euo pipefail
source "$(dirname "$0")/gui-lock.sh"
-RUNS=${RUNS:-3}
-SETTLE_SECONDS=${SETTLE_SECONDS:-20}
+RUNS=${RUNS:-5}
+IDLE_SECONDS=${IDLE_SECONDS:-10}
+FOLDER=${FOLDER:?set FOLDER=<folder to open>}
IFS=';' read -r -a apps <<< "${APPS:?set APPS=\"name=command;...\"}"
+scratch=$(mktemp -d)
+trap 'rm -rf "$scratch"; [[ -n ${PORT_GUI_LOCK_HELD:-} ]] || rm -rf /tmp/port-gui.lock' EXIT
+swiftc -O "$(dirname "$0")/bench-window.swift" -o "$scratch/bench-window"
+
+now() {
+ perl -MTime::HiRes=time -e 'printf "%.3f", time'
+}
descendant_pids() {
local pid=$1 child
@@ -20,6 +38,16 @@ descendant_pids() {
done
}
+# CPU seconds of the live processes of the tree under $1; ps prints time as [hh:]mm:ss.cc.
+tree_cpu() {
+ ps -A -o pid=,ppid=,time= | awk -v root="$1" '
+ { parent[$1] = $2; n = split($3, t, ":"); s = 0; for (i = 1; i <= n; i++) s = s * 60 + t[i]; cpu[$1] = s }
+ END {
+ for (p in cpu) { q = p; while (q in parent && q != root && q > 1) q = parent[q]; if (q == root) total += cpu[p] }
+ printf "%.2f", total
+ }'
+}
+
footprint_kb() {
local line value unit
line=$(timeout 30 footprint -p "$1" 2>/dev/null | rg -m1 'Footprint:') || return 1
@@ -33,18 +61,49 @@ footprint_kb() {
}
# The extension host: bootstrap-exthost.js in its arguments (port), or an Electron utility process whose
-# environment has VSCODE_ESM_ENTRYPOINT=vs/workbench/api/node/extensionHostProcess (reference).
+# environment has VSCODE_ESM_ENTRYPOINT=vs/workbench/api/node/extensionHostProcess (VS Code).
is_extension_host() {
ps -E -o command= -p "$1" | rg -q 'bootstrap-exthost|VSCODE_ESM_ENTRYPOINT=vs/workbench/api/node/extensionHostProcess'
}
-# Prints "<total kb> <extension host kb>".
+# Prints "<window s> <ready s> <cpu s> <idle %> <memory MB> <extension host MB> <quit s>".
measure_once() {
- local command=$1 data_dir pid p kb total=0 exthost=0
- data_dir=$(mktemp -d)
- ZED_STATELESS=1 bash -c "exec $command --user-data-dir '$data_dir'" >/dev/null 2>&1 &
+ local command=$1 dir=$2 start pid shown ready cpu before after p kb total=0 exthost=0 pids quit_start quit
+ start=$(now)
+ bash -c "exec $command --disable-workspace-trust --user-data-dir '$dir/user-data' --extensions-dir '$dir/extensions' '$FOLDER'" >/dev/null 2>&1 &
pid=$!
- sleep "$SETTLE_SECONDS"
+ if ! shown=$("$scratch/bench-window" wait "$pid" 60); then
+ echo "bench: $command showed no window in 60 s" >&2
+ kill -9 $(descendant_pids "$pid") 2>/dev/null || true
+ return 1
+ fi
+ ready=
+ local sample_start quiet_start= quiet_samples=0
+ after=$(tree_cpu "$pid")
+ until [[ -n $ready ]]; do
+ before=$after
+ sample_start=$(now)
+ sleep 0.5
+ after=$(tree_cpu "$pid")
+ if awk -v a="$after" -v b="$before" 'BEGIN { exit !(a - b < 0.05) }'; then
+ if ((quiet_samples == 0)); then
+ quiet_start=$sample_start
+ cpu=$before
+ fi
+ quiet_samples=$((quiet_samples + 1))
+ ((quiet_samples < 4)) || ready=$quiet_start
+ else
+ quiet_samples=0
+ fi
+ if [[ -z $ready ]] && awk -v t="$sample_start" -v s="$start" 'BEGIN { exit !(t - s > 180) }'; then
+ echo "bench: CPU of $command did not settle in 180 s" >&2
+ kill -9 $(descendant_pids "$pid") 2>/dev/null || true
+ return 1
+ fi
+ done
+ sleep "$IDLE_SECONDS"
+ local idle
+ idle=$(awk -v a="$(tree_cpu "$pid")" -v b="$after" -v s="$IDLE_SECONDS" 'BEGIN { printf "%.1f", (a - b) / s * 100 }')
for p in $(descendant_pids "$pid"); do
kb=$(footprint_kb "$p") || continue
total=$((total + kb))
@@ -52,38 +111,58 @@ measure_once() {
exthost=$((exthost + kb))
fi
done
- # Bounded teardown: one Electron run hung for 25 min with plain kill + wait (cause not found).
- local pids
- pids=$(descendant_pids "$pid" | sort -rn)
- kill $pids 2>/dev/null || true
- sleep 3
- kill -9 $pids 2>/dev/null || true
+ pids=$(descendant_pids "$pid")
+ quit_start=$(now)
+ "$scratch/bench-window" quit "$pid"
+ quit=
+ for _ in $(seq 600); do
+ # shellcheck disable=SC2086
+ if ! ps -o pid= -p "$(tr '\n' ',' <<< "$pids" | sed 's/,$//')" >/dev/null; then
+ quit=$(awk -v e="$(now)" -v s="$quit_start" 'BEGIN { printf "%.2f", e - s }')
+ break
+ fi
+ sleep 0.05
+ done
+ if [[ -z $quit ]]; then
+ echo "bench: $command did not quit in 30 s, left:" >&2
+ ps -o pid=,command= -p "$(tr '\n' ',' <<< "$pids" | sed 's/,$//')" | cut -c1-200 >&2 || true
+ # shellcheck disable=SC2086
+ kill -9 $pids 2>/dev/null || true
+ return 1
+ fi
wait "$pid" 2>/dev/null || true
- rm -rf "$data_dir"
- echo "$total $exthost"
+ awk -v w="$shown" -v r="$ready" -v s="$start" -v c="$cpu" -v i="$idle" -v t="$total" -v x="$exthost" -v q="$quit" \
+ 'BEGIN { printf "%.2f %.2f %.2f %s %.0f %.0f %s\n", w - s, r - s, c, i, t / 1024, x / 1024, q }'
}
-median_mb() {
- printf '%s\n' "$@" | sort -n | awk '{ v[NR] = $1 } END { m = NR % 2 ? v[(NR + 1) / 2] : (v[NR / 2] + v[NR / 2 + 1]) / 2; printf "%.1f", m / 1024 }'
+median() {
+ printf '%s\n' "$@" | sort -n | awk '{ v[NR] = $1 } END { m = NR % 2 ? v[(NR + 1) / 2] : (v[NR / 2] + v[NR / 2 + 1]) / 2; print m }'
}
-# macOS ships bash 3.2: no associative arrays, so samples sit at the app's index.
-totals=()
-exthosts=()
-for ((run = 1; run <= RUNS; run++)); do
+metrics=(window_s ready_s cpu_s idle_pct memory_mb exthost_mb quit_s)
+# macOS ships bash 3.2: no associative arrays, so the samples of app i, metric m sit at index i * 7 + m.
+samples=()
+for i in "${!apps[@]}"; do
+ mkdir -p "$scratch/$i/user-data/User" "$scratch/$i/extensions"
+ echo "${SETTINGS:-{\}}" > "$scratch/$i/user-data/User/settings.json"
+done
+for ((run = 0; run <= RUNS; run++)); do
for i in "${!apps[@]}"; do
- echo "run $run/$RUNS: ${apps[$i]%%=*}" >&2
- read -r total exthost <<< "$(measure_once "${apps[$i]#*=}")"
- totals[$i]="${totals[$i]:-}$total "
- exthosts[$i]="${exthosts[$i]:-}$exthost "
+ echo "run $run/$RUNS (0 is the warm-up): ${apps[$i]%%=*}" >&2
+ result=$(measure_once "${apps[$i]#*=}" "$scratch/$i")
+ read -r -a values <<< "$result"
+ echo " ${values[*]}" >&2
+ ((run > 0)) || continue
+ for m in "${!metrics[@]}"; do
+ samples[i * 7 + m]="${samples[i * 7 + m]:-}${values[$m]} "
+ done
done
done
-printf 'app\tmedian MiB\tsamples KB\n'
+printf 'app\tmetric\tmedian\tsamples\n'
for i in "${!apps[@]}"; do
- name=${apps[$i]%%=*}
- # shellcheck disable=SC2086
- printf '%s\t%s\t%s\n' "$name" "$(median_mb ${totals[$i]})" "${totals[$i]}"
- # shellcheck disable=SC2086
- printf '%s exthost\t%s\t%s\n' "$name" "$(median_mb ${exthosts[$i]})" "${exthosts[$i]}"
+ for m in "${!metrics[@]}"; do
+ # shellcheck disable=SC2086
+ printf '%s\t%s\t%s\t%s\n' "${apps[$i]%%=*}" "${metrics[$m]}" "$(median ${samples[i * 7 + m]})" "${samples[i * 7 + m]}"
+ done
done
diff --git a/port/tools/bench-window.swift b/port/tools/bench-window.swift
new file mode 100644
index 00000000000..6a8c1eced96
--- /dev/null
+++ b/port/tools/bench-window.swift
@@ -0,0 +1,36 @@
+// Used by port/tools/bench: swiftc -O port/tools/bench-window.swift -o <bin>
+// <bin> wait <pid> <timeout s>: prints the epoch time (s) at which <pid> first owns an on-screen window, exit 1 on timeout.
+// <bin> quit <pid>: sends <pid> the quit Apple event, as Cmd+Q from the Dock does.
+import AppKit
+
+let args = CommandLine.arguments
+guard args.count >= 3, let pid = pid_t(args[2]) else {
+ FileHandle.standardError.write("usage: bench-window wait <pid> <timeout s> | quit <pid>\n".data(using: .utf8)!)
+ exit(2)
+}
+
+switch args[1] {
+case "wait":
+ let deadline = Date().addingTimeInterval(Double(args[3])!)
+ while Date() < deadline {
+ let windows = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID) as! [[String: Any]]
+ // Layer 0 and wider than 400 pt: the workbench window, not a menu bar extra or a splash.
+ let shown = windows.contains { window in
+ let bounds = window[kCGWindowBounds as String] as! [String: CGFloat]
+ return window[kCGWindowOwnerPID as String] as! pid_t == pid && window[kCGWindowLayer as String] as! Int == 0 && bounds["Width"]! > 400
+ }
+ if shown {
+ print(String(format: "%.3f", Date().timeIntervalSince1970))
+ exit(0)
+ }
+ usleep(10_000)
+ }
+ exit(1)
+case "quit":
+ guard let app = NSRunningApplication(processIdentifier: pid), app.terminate() else {
+ FileHandle.standardError.write("bench-window: no app with pid \(pid) took the quit event\n".data(using: .utf8)!)
+ exit(1)
+ }
+default:
+ exit(2)
+}