Skip to content

perf: answer a bare version flag without loading the command graph - #40

Merged
escidmore merged 1 commit into
escidmore:mainfrom
Freudator86:perf/version-fast-path
Aug 20, 2026
Merged

escidmore merged 1 commit into
escidmore:mainfrom
Freudator86:perf/version-fast-path

Conversation

@Freudator86

Copy link
Copy Markdown

What this changes

bin/forgejo-axi.ts statically imported src/cli.js, so -v, -V and --version paid for the whole command graph before printing one line. That is the trap principle 10 names by name, and axi-sdk-js ships tryFastPath for exactly it.

The entry point now routes a bare version flag through the SDK's dependency-free fast path, and imports the command graph dynamically for everything else. The full CLI stays the single owner of every other argv shape, including a version flag in any position other than a bare one.

The SDK pin moves 0.1.9 -> 0.1.10, the first release exporting axi-sdk-js/fast-path.

Measurement

20 runs each, same shell, this machine:

ms/run
bare node -e "" floor 37
before 73
after 57

Roughly half the startup tax removed.

The residual, stated rather than left for you to find

src/version.ts imports readNearestPackageJson from the axi-sdk-js barrel, and that barrel re-exports cli, errors, hooks and update. So the fast path still loads the SDK index even though it no longer loads this tool's command graph. That is where the remaining ~20 ms sits.

I measured the alternative -- a leaf src/version.ts reading the nearest package.json with node builtins only -- at 56 ms/run against a 42 ms floor in the same session, so about 4 ms better than this PR. That is inside the run-to-run noise I saw on the floor itself, and it would mean hand-rolling a helper the SDK already owns. I judged that a bad trade and left it out, but it is your call and I will add it if you want it.

Verification

  • npm run check passes: lint, typecheck, 237 tests, smoke.
  • scripts/smoke.mjs now asserts the value rather than merely that something was printed: --version, -v and -V must each equal the version in package.json, and --help must still reach the full command graph. A fast path that answered with anything other than the package version would otherwise be a faster wrong answer, and nothing would have caught it.

Live lanes: neither was run. This change touches no API request, response handling, or fixture, so docs/live-test-matrix.md does not call for one. Saying so explicitly per CONTRIBUTING rather than leaving it unstated.

bin/forgejo-axi.ts statically imported src/cli.js, so -v, -V and --version
paid for the whole command graph before printing one line. That is the trap
principle 10 names, and axi-sdk-js ships tryFastPath for exactly it.

The entry point now routes a bare version flag through the SDK's dependency-
free fast path and imports the command graph dynamically for everything else,
so the full CLI stays the single owner of every other argv shape including a
version flag in any other position. The SDK pin moves to 0.1.10, the first
release exporting axi-sdk-js/fast-path.

Measured on this machine, 20 runs each: 73 ms/run before, 57 ms/run after,
against a 37 ms/run bare-node floor -- roughly half the startup tax removed.

The smoke script now asserts the value, not just that something was printed:
all three flags must equal the package version, and --help must still reach
the full command graph.
@escidmore
escidmore merged commit 85abacd into escidmore:main Aug 20, 2026
5 checks passed
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