Skip to content

refactor(opencode): lazy-load commands so --version skips full startup - #50219

Closed
Fluffy-Bunny-23 wants to merge 1 commit into
anomalyco:devfrom
Fluffy-Bunny-23:lazy-cli-commands
Closed

Fluffy-Bunny-23 wants to merge 1 commit into
anomalyco:devfrom
Fluffy-Bunny-23:lazy-cli-commands

Conversation

@Fluffy-Bunny-23

@Fluffy-Bunny-23 Fluffy-Bunny-23 commented Sep 20, 2026 •

Copy link
Copy Markdown

Issue for this PR

No linked issue. opencode --version prints a compile-time constant but loads the entire static command graph first, which stretches into seconds on a loaded box.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Command modules now load only when their command actually runs. --version and top-level --help start just yargs plus a few dependency-free helpers. The default TUI command keeps a synchronous builder because yargs needs it to render top-level help, and its runtime loads on dispatch like everything else. No command behaves differently than before.

On my machine (8-core Fedora box, compiled binary built with script/build.ts --single --skip-install --skip-embed-web-ui), opencode --version x5:

before after
real (mean) 1.48s 0.13s
user (mean) 1.91s 0.13s
worst run 1.74s 0.15s

Full runs, before real: 1.74, 1.50, 1.47, 1.38, 1.30s. After real: 0.12, 0.13, 0.15, 0.12, 0.13s. User CPU beat wall clock on every before run, so this was CPU-bound startup, not disk.

For cold page cache I evicted the binary pages with posix_fadvise and ran each side twice: before real 2.09s and 1.90s, after real 0.15s and 0.13s. So the worst case improves from about two seconds to well inside the target.

How did you verify your code works?

bun typecheck is clean and oxlint exits 0 on the touched files. Tests pass: thread (11, including live-spawn dispatch tests), help snapshots (34) plus error and smoke tests, attach, attention. --help, run --help, mcp --help, and the unknown-flag error output are byte-identical before and after. I also launched the TUI once and ran one run invocation on the built binary, both fine.

Screenshots / recordings

No UI change, so none.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

This PR was autonomously generated with T3 Code via muse-spark-1.3-contributor-free on opencode

Implemented With: T3 Code via muse-spark-1.3-contributor-free on opencode
Copilot AI lite review requested due to automatic review settings September 20, 2026 19:40

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.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions

Copy link
Copy Markdown
Contributor

Hey! Your PR title perf(cli): cut --version startup from ~1.5s to ~0.13s with lazy commands doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Sep 20, 2026
@github-actions github-actions Bot closed this Sep 20, 2026
@Fluffy-Bunny-23 Fluffy-Bunny-23 changed the title perf(cli): cut --version startup from ~1.5s to ~0.13s with lazy commands refactor(opencode): lazy-load commands so --version skips full startup Sep 21, 2026
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:title needs:compliance This means the issue will auto-close after 2 hours. labels Sep 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@Fluffy-Bunny-23

Copy link
Copy Markdown
Author

I am sorry for the incorrectly formatted PR. I have fixed the formatting issues.

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