Repository navigation
perf: answer a bare version flag without loading the command graph - #40
Merged
Merged
Conversation
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.
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.
What this changes
bin/forgejo-axi.tsstatically importedsrc/cli.js, so-v,-Vand--versionpaid for the whole command graph before printing one line. That is the trap principle 10 names by name, andaxi-sdk-jsshipstryFastPathfor 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 exportingaxi-sdk-js/fast-path.Measurement
20 runs each, same shell, this machine:
node -e ""floorRoughly half the startup tax removed.
The residual, stated rather than left for you to find
src/version.tsimportsreadNearestPackageJsonfrom theaxi-sdk-jsbarrel, and that barrel re-exportscli,errors,hooksandupdate. 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.tsreading the nearestpackage.jsonwith 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 checkpasses: lint, typecheck, 237 tests, smoke.scripts/smoke.mjsnow asserts the value rather than merely that something was printed:--version,-vand-Vmust each equal the version inpackage.json, and--helpmust 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.mddoes not call for one. Saying so explicitly per CONTRIBUTING rather than leaving it unstated.