Skip to content

perf(desktop): ship the bundled CLI version instead of spawning for it - #49762

Merged
Hona merged 2 commits into
v2from
cli-version-cache
Sep 18, 2026
Merged

Hona merged 2 commits into
v2from
cli-version-cache

Conversation

@Hona

@Hona Hona commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Every launch spawned the bundled 240 MB CLI executable just to read its version string, and the main process waited ~380 ms for it before the background service, WSL support and — because windows are created after every layer has built — the window itself. On the first launch after an install or update it was worse: ~3 s while the antivirus scanned the freshly staged binary.

main.log, production 2.0.8
28.430  v2 CLI command started   { args: ['--version'] }
28.810  v2 CLI command completed { stdout: 'opencode v2.0.8' }      ← 380 ms, every launch
28.839  v2 CLI background service ready
29.199  main window visible

Two commits:

  1. Ship the version with the build. Prebuild copies the CLI out of an npm package directory (@opencode/cli-<target>@<version> for dev, OPENCODE_CLI_DIST/<target>/ for beta/prod) whose package.json version is exactly the string the executable prints for --version. It now writes that to resources/opencode-cli.version; electron-builder packages it next to the executable and afterPack fails when it is missing or empty. The desktop reads it first — a packaged app never spawns the CLI for its version, first launch included.
  2. Remember it per executable as the fallback for an executable that arrived without the file: keyed by path, size and mtime in the settings store, spawned once per installed build.
   712  main   starting v2 background service
   715  main   v2 CLI executable resolved
   719  main   v2 CLI version bundled        ← was: command started … completed, +380 ms
   811  main   v2 CLI executable staged
   841  main   v2 CLI background service ready

(bench timeline, fresh profile, so the 90 ms staging copy of the executable is also visible)

Measured with bun run bench:startup (#49758): packaged v2 build, isolated home, warm service, 5 launches, median ms since process spawn.

milestone baseline this PR
service ready 818 479
renderer process starts 851 512
window visible 1,085 778
first paint 1,219 899
shell visible 1,289 961

@Hona
Hona requested a review from Brendonovich as a code owner September 18, 2026 12:43
Copilot AI lite review requested due to automatic review settings September 18, 2026 12:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Every launch spawned the bundled 200 MB CLI executable for --version and
waited ~380 ms for it before the background service, WSL support and,
because windows are created after every layer builds, the window itself.
The version only changes when an update replaces the executable, so keep
it in the settings store keyed by the executable's path, size and mtime
and only spawn when that identity changes.

Packaged build, warm service, 5 launches (median ms since spawn):
renderer process 851 -> 512, window visible 1085 -> 778,
shell visible 1289 -> 961.
The prebuild copies the CLI out of an npm package directory whose
package.json version is exactly what the executable prints for
--version, so write it to resources/opencode-cli.version and package it
with the executable. The desktop reads that file first, which means a
packaged app never spawns the CLI for its version, including the first
launch after an install or update (previously ~400 ms, or seconds while
the antivirus scanned the fresh binary). The per-identity cache remains
as the fallback for an executable without the file. afterPack fails the
package when the version file is missing or empty.
@Hona
Hona force-pushed the cli-version-cache branch from 5c2eaad to a0f5811 Compare September 18, 2026 23:33
@Hona Hona changed the title perf(desktop): remember the bundled CLI version between launches perf(desktop): ship the bundled CLI version instead of spawning for it Sep 18, 2026
@Hona
Hona merged commit 988a66c into v2 Sep 18, 2026
12 checks passed
@Hona
Hona deleted the cli-version-cache branch September 18, 2026 23:36
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
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.

2 participants