Repository navigation
perf(cli): load zod at a queue transfer verb's first parse, not with every rig queue command - #4080
Conversation
…every rig queue command The queue command module registers `queue transfer`, so its top-level zod import put zod on every `rig queue list` and `show` start-up, which lazy-program.ts otherwise keeps to the queue command's own imports. The schemas are now built from a dynamic import on first use, as the module already loads @openrig/daemon/queue-transfer-records. A test loads the queue command with zod mocked to throw.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
openrig-review
left a comment
There was a problem hiding this comment.
Reviewed and tested at b8dd663: rig queue list and show no longer load zod at start-up, because the transfer verbs load it at their first parse, so those reads are back to their earlier speed. Transfer validation, errors and outputs are unchanged. Approving this head so the macOS package tests run.
What this changes
rig queue listandrig queue showrun about 45–85 ms faster again, back to 0.7.24's time. The output is unchanged.The CLI loads only the module of the command being run (
lazy-program.ts). The queue command module registersqueue transfer(#3917), andqueue-transfer.tsimported zod at the top level and built two schemas when it loaded. So everyrig queuecommand,listandshowincluded, loaded zod's roughly 95 modules at start-up, although only the transfer verbs use it.queue-transfer.tsnow builds its three schemas from a dynamicimport("zod")at a transfer verb's first parse. It already loads@openrig/daemon/queue-transfer-recordsthe same way. The type-onlyimport("zod")in type positions compiles away. Every use is inside an async action, and a parse error is a rejection from the same action as before.Evidence
Setup: one Linux test machine (4 vCPU, Node 22.23.4) with one daemon, the current version with no kernel, on a synthetic queue of about 350 rows. Three CLIs read the same rows:
f9e55998, before this change (the queue command path is unchanged from there to this PR's base);dist/commands/queue-transfer.js. A recursive diff of the two installs names that file alone.Request sequence: each read sends the same two requests in every arm,
GET /healthzand then the read (logged through a recording proxy). So the cost isn't in what the CLI asks for.Modules loaded:
queue list/showview showB's extra files are
queue-transfer.jsand zod's 95, nothing else.Wall and CPU time: medians in ms of 60 runs per arm and read. They come from two runs of 18 blocks each, with the arms rotated so each is in each position equally often. Each block's first run is discarded.
queue list --jsonqueue list --json --state blockedqueue list --json --ownedqueue show <id> --full --json, five rowsview show escalations --json(control)view show pickup --json(control)The same URLs over curl took 2–62 ms in every arm. The machine is shared, so single blocks vary by tens of ms. CPU time is the steadier signal: B costs about 80–110 ms more than A on every queue read, and P matches A.
Output: the output is byte-identical between B and P for:
queue listandqueue show;queueandqueue transferhelp.The two views match once their
generatedAttime is normalized. A's output equals B's for all of these except the help, where B also listsqueue transfer.Tests
The new test,
packages/cli/test/queue-command-startup.test.ts, loads the queue command module with zod mocked to throw, then buildsrig queuewithlist,showandtransfer(with its subcommands). Without this change it fails atqueue-transfer.ts'simport { z } from "zod"("zod was loaded with the queue command module"); with it, it passes.On Linux (Node 22.23.4), from the base's source plus this commit:
npm run buildandnpm run lintpass.queue-transfer,queue-import,queue-export,lazy-program,bin-wrapperand the new test pass (6 files, 51 tests).release-surface.test.ts's non-existent-ref case, which needs a git checkout ("without a repo it cannot run"), and the test copy was an archive.🤖 Generated with Claude Code
Summary by CodeRabbit