perf(cli): enable V8 compile cache in bin/run (#90)#93
Conversation
Call module.enableCompileCache() before the @oclif/core import so the CLI's own dist/ graph, oclif and the rest of the dependency closure get bytecode- cached across invocations. Optional-chained so it is a no-op on Node < 22.8 and never throws (failures are reported via its return value). Honors NODE_COMPILE_CACHE and NODE_DISABLE_COMPILE_CACHE=1. Recovers ~0.5-1s of per-command startup on slow hosts on second-and-later runs; pkc-js already self-caches its own graph, so this covers the part it does not (the CLI's own files + oclif + other deps). Adds test/cli/compile-cache.test.ts: spawns the built bin/run --version with an isolated TMPDIR and asserts the default cache dir is populated from bin/run itself (and that NODE_DISABLE_COMPILE_CACHE=1 writes nothing).
The default (non-quiet) list spins up every community over RPC to fill the 'started' column, which is 2-30s slower than -q on a busy daemon. Document that in the -q flag summary (and the generated README).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe PR enables V8 compile cache at CLI startup for faster subsequent invocations, documents the ChangesDocumentation: --quiet Flag Performance Clarification
V8 Compile Cache Startup Enablement
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
bin/runnow callsmodule.enableCompileCache()before the dynamic@oclif/coreimport, so the CLI's owndist/graph + oclif + the rest of the dependency closure get bytecode-cached across invocations. Optional-chained (enableCompileCache?.()) so it's a no-op on Node < 22.8 and never throws (failures are reported via its return value). HonorsNODE_COMPILE_CACHEandNODE_DISABLE_COMPILE_CACHE=1.community list-qdoc — the flag summary (and generated README) now note that-qis much faster because it skips the per-communitystartedlookup.Implements #90. Documents part of #76 (the real fix for the
started-column cost is tracked upstream in pkcprotocol/pkc-js#141).Why
Profiling
bitsocial community liston a slow host (Node v22.22.2, pkc-js 0.0.47) decomposed as:node -e 0@pkcprotocol/pkc-jsalonebitsocial --version(oclif boot)community list -q(floor)community list(full)pkc-js already enables the compile cache for its own graph, but everything the CLI loads around it (its own ~600
dist/files, oclif, other deps) was still compiled uncached on every run. This recovers ~0.5–1s of that per-command floor on second-and-later runs; the win is larger on real commands than on--version(which compiles less of the graph).Testing
npm run test:cligreen: 301 passed, 1 skipped, 0 failed (39 files, incl. the kubo/daemon integration suite).test/cli/compile-cache.test.tsspawns the builtbin/run --versionwith an isolatedTMPDIR(andNODE_COMPILE_CACHEstripped) and asserts the default cache dir is populated frombin/runitself, not from an inherited env var; a second case assertsNODE_DISABLE_COMPILE_CACHE=1writes nothing and the CLI still works. Skipped on Node < 22.8.--version: 0.55s → 0.46s with the cache warm.Drawbacks (low)
os.tmpdir()/node-compile-cache(ephemeral; cleared on reboot / per container lifetime).noexecor Node < 22.8, it's a no-op — never throws. Entries are validated by source hash + Node/V8 version, so stale/corrupt entries are recompiled, not mis-executed.Notes
community listspecifically is still thestartedcolumn (community list: default (non-quiet) is 2-30s slower than -q because the 'started' column spins up every community #76) — deliberately documentation-only here; structural fix proposed in feat(rpc): carry per-community state in the communities subscription (pkc.communities -> {address, started}[]) so RPC clients don't instantiate every community pkcprotocol/pkc-js#141.Summary by CodeRabbit
Performance
Documentation
--quietflag provides faster performance by skipping per-community lookups.Tests