perf: fast-path completion/version/shell-scripts to bypass full discovery#898
Merged
perf: fast-path completion/version/shell-scripts to bypass full discovery#898
Conversation
… discovery Lightweight commands (--get-completions, --version, completion <shell>) now resolve before any heavy module loading. Key changes: - New completion-fast.ts: manifest-based completion + shell script generators with zero dependency on registry/discovery/cli modules - main.ts: static imports replaced with dynamic import() for the full startup path so the fast path never pays the cost of loading discovery, registry, Commander, hooks, etc. - USER_CLIS_DIR inlined to avoid importing the entire discovery module - completion.ts: removed manifest functions (moved to completion-fast.ts), now only used as fallback when manifest is unavailable
1. --version fast path: only match when argv[0] is --version/-V, not anywhere in argv. Prevents intercepting `opencli gh --version` which should pass through to the subcommand. 2. Completion fast path: require ALL manifests to exist (hasAllManifests), not just one. If user clis dir exists but has no manifest, fall back to full discovery so user adapters aren't silently dropped. If user clis dir doesn't exist at all, skip its manifest requirement since there are no user adapters to miss.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--get-completions: readscli-manifest.jsondirectly via newcompletion-fast.ts, never loads registry/discovery/Commander--version/-V: printsPKG_VERSIONand exits immediatelycompletion <shell>: prints shell script (bash/zsh/fish) without any discoveryimport()so fast paths never pay the import cost ofdiscovery.js,registry.js,cli.js,hooks.js,node-network.js,update-check.js--get-completionsstill falls through to full discovery pathFiles changed
src/completion-fast.ts(NEW) — lightweight manifest reader + shell script generators, depends only onnode:fssrc/main.ts— fast-path checks before discovery; heavy imports converted to dynamicimport()src/completion.ts— removed manifest functions (moved tocompletion-fast.ts), cleaned up unusedfsimportDesign decisions
USER_CLIS_DIRinlined aspath.join(os.homedir(), '.opencli', 'clis')to avoid importing the entirediscovery.tsmoduleBUILTIN_COMMANDSlist duplicated incompletion-fast.ts(intentional — avoids any transitive dependency onregistry.js)--helpintentionally NOT fast-pathed — it depends on the full Commander tree (per codex-mini0 review)discoverPlugins()Context
P0a from performance analysis discussion: #893 (comment)...
Discussed with @codex-mini0 in #OpenCLI thread.
Test plan
tsc --noEmitpassesopencli --versionreturns version without delayopencli completion zshprints script without delayopencli --get-completions twitterreturns completions quickly (with manifest present)time opencli --versionbefore/after to measure improvement