Skip to content

perf(cli): cut Windows short-command startup by 40-58% - #416

Merged
mrnasil merged 1 commit into
mainfrom
perf/windows-startup
Nov 7, 2026
Merged

mrnasil merged 1 commit into
mainfrom
perf/windows-startup

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 6, 2026

Copy link
Copy Markdown
Member

Re-ran the benchmarks: the last process run was 2026-10-16 and the last criterion run was 2026-09-11. On Windows, --version had drifted to 17 ms, while an empty Rust main starts in ~10 ms on the same host. Three fixes:

  1. Delay-load system DLLs (crates/cli/build.rs, MSVC only). user32, shell32, combase, oleaut32, ws2_32, bcrypt, userenv and advapi32 cost ~6 ms per process whether or not they were used. An empty main linked against the same DLLs starts in 15.9 ms instead of 9.6 ms. With /DELAYLOAD, they load on first call.
  2. hide_possible_values on the dynamic clap value parsers. While building the command, clap asks every argument for its possible values to decide whether long help exists. The provider, model, session-id and auth-provider parsers read config.toml and opened the session DB to answer, on every invocation (~8 ms). Completion scripts are byte-identical before and after (bash, zsh, fish, PowerShell). --help no longer prints the full model list or this machine's session ids.
  3. Legacy-instance migration checks ~/.whycodes first. Config::load resolved the pre-0.7 ProjectDirs known folders (shell32 + COM) before it checked whether there was anything to migrate. Once (1) deferred those DLLs, this cost ~9 ms. Behavior is unchanged, because the copy step already returned early in that case. Includes a new test for the settled-home path.

The binary size jump (18.5 → 28.9 MB) is the Windows embedded-shell default. A build without it starts no faster, so the extra size does not cost startup time.

Numbers (Windows, Ryzen 7 3800X, interleaved, 40 runs, median)

Case Before After
--version 17.5 ms 10.5 ms
--help 26.1 ms 10.8 ms
config show 42.2 ms 23.2 ms
session list 44.1 ms 25.8 ms
stats 40.1 ms 24.6 ms
peak RSS config show 14.2 MB 7.6 MB
TUI harness spawn-to-exit 20.0 ms 12.5 ms

Criterion hot paths are flat or faster: ANSI render of a 200-line fence went from 40.9 to 14.2 ms, and the index is slightly faster. The exception is assess on short commands. The #294 parser adds ~1 µs of fixed cost there, which is documented and left alone (40× under budget). docs/benchmarks.md, docs/bench-results.json and the README Windows column are updated.

Checks

  • cargo test -p whycodes-config --lib: 164 passed
  • cargo test -p whycodes-cli: all green except 4 unit tests and 2 cli_args plain-REPL tests that fail identically on clean main on this Windows machine (lockfile PIDs, upgrade zip, run_shell, a debug-only stack overflow in --plain)
  • fmt, clippy (cli, config), panic / swallowed-error / dependency / secrets ratchets, bench ceilings: ok
  • whycodes-config coverage locally: every new line covered. The only gaps are 3 non-UTF-8-filename branches that Windows cannot exercise, which is pre-existing.

🤖 Generated with Claude Code

Re-ran the benchmarks (last process run 2026-10-16, last criterion run
2026-09-11). `--version` had drifted to 17 ms on Windows while an empty
Rust exe starts in ~10 ms on the same host. Three fixes:

- Delay-load user32, shell32, combase, oleaut32, ws2_32, bcrypt, userenv
  and advapi32 (MSVC only, build.rs). Loading them eagerly cost ~6 ms per
  process whether or not they were used.
- `hide_possible_values` on the dynamic clap value parsers. clap asked
  them for their values while building the command, which read
  config.toml and opened the session database on every invocation
  (~8 ms). Completion scripts are byte-identical; `--help` no longer
  lists every model id and local session ids.
- Skip the pre-0.7 legacy-instance migration before resolving Windows
  known folders when ~/.whycodes already holds instance files (~9 ms
  once the DLLs above are deferred). Behavior is unchanged: the copy
  step already returned early in that case.

Interleaved medians, before -> after: --version 17.5 -> 10.5 ms,
--help 26.1 -> 10.8 ms, config show 42.2 -> 23.2 ms, session list
44.1 -> 25.8 ms. Peak RSS of config show 14.2 -> 7.6 MB. TUI harness
spawn-to-exit 20.0 -> 12.5 ms. Criterion hot paths are flat or faster
except short `assess` calls (~1 us fixed cost from the #294 parser,
documented and left alone).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil force-pushed the perf/windows-startup branch from 4ff1128 to ea0a47d Compare November 7, 2026 00:09
@mrnasil
mrnasil merged commit 091bf4e into main Nov 7, 2026
7 checks passed
@mrnasil
mrnasil deleted the perf/windows-startup branch November 7, 2026 00:16
mrnasil added a commit that referenced this pull request Nov 9, 2026
…ms) (#441)

With the system DLLs delay-loaded (#416), the dynamic CRT was the last
thing loading before main: VCRUNTIME140 plus nine api-ms-win-crt-* DLLs.
+crt-static for MSVC targets removes them. Released v0.6.36 vs this tree,
interleaved, 2x300 runs: 6.88 -> 6.43 ms median, p95 7.75 -> 7.07 ms.
The binary no longer needs the VC++ redistributable.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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