perf: lazy-load inquirer and defer telemetry init to halve startup latency#286
Merged
Merged
Conversation
…tency The CLI had a ~640ms startup overhead even for `--help` / `--version` due to two bottlenecks: 1. `inquirer` (~200ms) was statically imported via `adr/create.ts` → `adr/index.ts` → `cli.ts`, forcing every invocation to pay the parse cost even when no interactive prompt was needed. 2. `initSentry()` + `initTelemetry()` (~150ms) were awaited before command registration, blocking `--help` / `--version` which never trigger the `preAction` hook where telemetry events are emitted. Fixes: - Lazy-load `inquirer` via dynamic `import()` at the 4 call sites that actually prompt: `adr/create.ts`, `init.ts`, `editor-detect.ts`, `login-flow.ts`. - Start telemetry/sentry init eagerly but only `await` it in the `preAction` hook (which `--help`/`--version` never reach). By the time a real command fires `preAction`, the init has usually already resolved concurrently, so the await is effectively free. - Add `ExitPromptError` re-throw to all 18 command catch blocks — the canonical ARCH-012 pattern was documented but not enforced. Without it, Ctrl+C during a prompt exits with code 1 (failure) instead of 130 (user cancellation). - Add automated rule `ARCH-012/exit-prompt-error-rethrow` to prevent future regressions — catches any async command action whose catch block is missing the re-throw guard. - Add startup latency budget tests (--help <1s, --version <1s, adr list <1.5s, check <2.5s) to catch import-time regressions. Result: `--help` drops from ~640ms to ~310ms (52% faster). Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Deploying archgate-cli with
|
| Latest commit: |
1f2ca11
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://87c790e7.archgate-cli.pages.dev |
| Branch Preview URL: | https://perf-lazy-load-startup-optim.archgate-cli.pages.dev |
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
inquirervia dynamicimport()at the 4 call sites that actually prompt (adr/create,init,editor-detect,login-flow), saving ~200ms on every invocation that doesn't need interactive promptsawaitin thepreActionhook, saving ~150ms for--help/--versionwhich never triggerpreActionExitPromptErrorre-throw to all 18 command catch blocks and a new automated rule (ARCH-012/exit-prompt-error-rethrow) to enforce it going forward--help<1s,--version<1s,adr list<1.5s,check<2.5s)Result:
--helpdrops from ~640ms to ~310ms (52% faster).Startup profile (before → after)
inquirerstatic importinitSentry() + initTelemetry()--helpTest plan
bun run validatepasses (lint, typecheck, format, 738 tests, 24/24 ADR rules, knip, build)--help,--version,adr list,checkall produce correct outputadr create,init) still load inquirer correctly when prompts are needed