Skip to content

perf(nx): cache the patchkit CLI, module packs and device images - #988

Merged
m-dwyer merged 2 commits into
mainfrom
tools/cache-producers
Dec 5, 2026
Merged

m-dwyer merged 2 commits into
mainfrom
tools/cache-producers

Conversation

@m-dwyer

@m-dwyer m-dwyer commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Why

Seven-day numbers: patchkit:cli 1,226 min at 0% hits, patchkit:device-images 744 min at 0%, patchkit:device-bytes 660 runs at 0%. The module pack and pack-aliases targets rebuilt on every gate run too. All five are cache: true now, on declared inputs.

First vs cached time (this machine, warm toolchain)

target first run cached
patchkit:cli 56 s (37 s after a one-line edit) 4-8 s
digikit/pluck:pack 6.3 s 4.8 s
core/dynfx:pack-aliases 9.2 s 5.0 s
patchkit:device-bytes (35 tasks) 9.1 s 5.9 s (1.2 s run)
patchkit:device-images (25 tasks) 30.8 s 5.5 s

Per-target times include dependencies; the first-run figures are lower bounds because dependencies were partly warm.

Input evidence (nx show target <t> inputs)

  • cli (572 files): Cargo.toml/lock, packages/patchkit plus the path-dependency crates (dkaddrmap, dkheader, dkprof, dksample, dksharc, dkupload, service-rules, emulator, runtime, services/), devices/, config/. Runtime: rustc -vV of the pinned toolchain, cargo profile env, firmware-hash.mjs --cf-native. Env: RUSTFLAGS group, CARGO_, CF_NATIVE_DIR.
  • pack (131 files): module sources, sdk/, ports/ (all port files and ports/fw), devices/, runtime services. Runtime: firmware hash with overrides, rust pin, node and pnpm versions. depOutputs: patchkit:cli binary and test keys.
  • pack-aliases (126 files): same groups plus the pack outputs of its modules.
  • device-bytes (116 files): module manifests, runtime/tests inputs, dep outputs of every .dko.json and the CLI.
  • device-images (173 files): adds devices/, ports/, manifests, and stock image bytes through firmware-hash.mjs --syx --overrides --module-files.

Hit, miss, revert hit

Second run hits for all five ([local cache]). One edit each, then revert:

  • cli: comment in packages/patchkit/src/abigen.rs: 0/1 hit, then 1/1 after revert.
  • pack: modules/machine/digikit/pluck/src/module.c: miss, revert 2/2.
  • pack-aliases: ports/fw/draw.toml: 1/3 (CLI hit, pack and aliases rebuilt), revert 3/3.
  • device-bytes: pluck module.toml: 33/35, revert 34/35 (the one non-cached dependency is outside this PR).
  • device-images: ports/fw/draw.toml: 23/25, revert 24/25.

Review gaps and closures

  • Module loader files beyond module.toml (payload bodies, registry index_table, system package) were missing from device-images: derived from the manifests (loaderFiles, --module-files).
  • Packs ignored ports/ and the env overrides: added ports/*.toml, ports/fw and the overrides through firmware-hash.mjs; PATCHKIT_MODULES refuses reuse.
  • The CLI did not hash CF_NATIVE_DIR or the kernels.rs it names: both added.
  • docs/TESTING.md no longer says these are uncached.

Static proof

  • test-plans --ref origin/main --count 22, before (clean origin/main lane) and after (branch), none FAILED: 21 of 22 plans identical. One differs: d4d0724 (feat(devices): take the dn2 runtime buffers from the firmware heap #967, edits devices/digitone-ii.toml) gains 9 tasks: test/dyn-dsp-hang:pack, test/stock-pool:pack, test/syspkg:pack, tom/tb303:pack, sdk:test-dsp and four workbench-ts-check. Cause: the producers now declare the CLI outputs as dependency outputs, and the CLI's inputs include devices/, so a device-profile edit is now seen to reach them. That is correct (the profile is compiled into the CLI) and was a missed selection before. No selection shrank.
  • mise run test:ledger before/after (both in one lane so artifacts match): 0 removed, 0 added, 0 moved.
  • test:changed: 19 tasks pass, rig preflight 0 problems; py_select checks pass.

🤖 Generated with Claude Code

m-dwyer and others added 2 commits December 5, 2026 22:08
…ce-images

patchkit:cli, every module pack and pack-aliases, patchkit:device-bytes and
patchkit:device-images were cache: false, so every gate run in every worktree
rebuilt them (0% hit over 7 days). They are cached on declared inputs now.

- cli: adds COMPILE_SOURCE.patchkit, Cargo.toml, Cargo.lock, .cargo, the rust pin,
  rustc version, profile and flag variables (shared rustEnvInputs with the
  hermetic rust-tests); outputs are the binary and the patchkit test keys.
- pack and pack-aliases: inputs were already complete; only the flag changes.
- device-bytes: adds the module manifests.
- device-images: adds devices, ports, ports/fw, the manifests, and the stock image
  bytes through firmware-hash.mjs --syx --overrides (new flag, images only).

Checked: second run hits, restored outputs are byte-identical, a one-line input
edit misses and the revert hits again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each missing input meant a stale cache hit and a false pass.

- device-images hashes the module files the loader opens beyond module.toml
  (payload bodies, registry index_table, system package), derived from the
  manifests by loaderFiles; firmware-hash.mjs --module-files
- pack and pack-aliases take ports/*.toml, ports/fw and the environment
  overrides (PATCHKIT_MODULES refuses reuse), through firmware-hash.mjs
- patchkit:cli hashes CF_NATIVE_DIR and the kernels.rs it names
- docs/TESTING.md: drop the stale "uncached" sentence, describe the inputs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@m-dwyer

m-dwyer commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator Author

[host] test:subset: --base origin/main
[host] conformance: none selected
[host] gate-device-smoke: device (17 halves)
[host] test:subset: skipped, selected by affected and left to the full tier (mise run test:all -- --all-affected or test:full): 219 device halves and conformance tasks of 50 projects: core/digikit-menu-memory-tests 2, core/digikit-menu 2, core/dynfx 2, core/fx 1, core/input 2, core/introblank 2, cor
[host] test:subset: 0 coupled and 0 zero-DSP tasks; core budget 12, 12 slots: 0 coupled and 0 zero-DSP start at once
[host] test:subset: rig preflight: 17 halves, 0 problems
[host] test:subset: prebuild: 84 dependency tasks of the selection in 15 Nx runs
[host] test:subset: pnpm nx:pilot run-many -t cli -p patchkit,plusdrive-format
[host] test:subset: pnpm nx:pilot run-many -t daemons -p digi-control
[host] test:subset: pnpm nx:pilot run-many -t test-assembly -p core/runtime
[host] test:subset: pnpm nx:pilot run-many -t pack -p test/sine,test/dyn-dn2,test/dyn-fx-gain,test/entry-demo,test/lfo-shape,test/lfo-shape-b,test/shortcut-demo,test/svc-test-user,test/svc-test,test/syspkg,core/services/shortcuts,core/services/machines,core/services/project,core/services/samples,cor
[host] test:subset: pnpm nx:pilot run-many -t package -p core/runtime
Total: 9m14s, failed (0).

@m-dwyer
m-dwyer merged commit f33c1f2 into main Dec 5, 2026
2 checks passed
@m-dwyer
m-dwyer deleted the tools/cache-producers branch December 5, 2026 12:45
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.

1 participant