Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): every `t3` CLI command re-parses the 13.5 MB bundle; Node's compile cache would cut `t3 --help` from ~550 ms to ~380 ms #19332

Closedbompus(GitHub profile, opens in a new tab) opened this issue 2 comments

What happened

The t3 CLI does not enable Node's V8 compile cache, so each invocation compiles the whole 13.5 MB server bundle again. Short commands pay this on every call (--help, pair, auth, project, service, trace), and so does npx t3 starting the server. The packaged desktop app already enables the cache for its backend (#13501), so the same bundle starts faster there than from the CLI.

Diagnosis

  • apps/desktop/src/compileCache.ts:24 calls NodeModule.enableCompileCache(...) and the desktop passes it to the backend with --require (apps/desktop/src/backend/DesktopBackendConfiguration.ts:594).
  • apps/server/src/compileCache.ts only flushes the cache (flushCompileCache, called from serverRuntimeStartup.ts:654). Nothing in apps/server/src/bin.ts or binCli.ts enables it, so outside the desktop there is no cache to flush.
  • A --cpu-prof of a packaged t3 help run attributed about 32% of samples to compilation and about 12% to garbage collection.

Measured on a vp pack build of upstream main (4d73e1d5cd), 11 interleaved runs per arm, synthetic empty home, nice -n 10, Node v26.11.1. The cached arm uses NODE_COMPILE_CACHE as a stand-in for the API call, after one populating run:

node dist/bin.mjs --helpMedianRange
No compile cache554 ms533-579
Warm compile cache381 ms361-419

That is 174 ms (31%) less per invocation, with disjoint ranges. A second measurement on the packaged binary (n=5 per arm) gave t3 help 698 ms against about 430 ms, and boot to the first WebSocket answer 1,097 ms against 916 ms on a warm empty home. The boot ranges overlap in their tails, so the --help result is the firmer one. The cache directory was about 10 MB.

Cheaper form: call NodeModule.enableCompileCache(<XDG cache>/t3code/compile-cache) in a try/catch at the top of apps/server/src/bin.ts, before the dynamic imports, reusing the directory policy from apps/desktop/src/compileCache.ts. The API call does not leak into child processes the way the NODE_COMPILE_CACHE variable would, which is why the desktop uses --require.

Not measured, and worth checking before a change: the first run after install pays about 10 MB of cache writes once; the single-executable build (useCodeCache: false in apps/server/vite.config.ts) embeds modules rather than files, so it needs a no-op check; and whether writing a cache directory from the CLI is acceptable on locked-down hosts is a product call.

Steps to reproduce

  1. cd apps/server && vp pack
  2. Time node dist/bin.mjs --help several times.
  3. Repeat with NODE_COMPILE_CACHE=/some/dir set (run once to populate, then time).

Version

upstream main 3213a0c77b (the CLI entry is unchanged from 4d73e1d5cd, where I measured)

Environment

Linux 7.2.9 (WSL2), Node v26.11.1, 16 vCPUs

Evidence

CPU profile and timing scripts are saved from the investigation. I can attach them on request.

#13501 (merged) added the compile cache for the packaged desktop backend only. #19256 (closed, unmerged) shipped a prebuilt cache inside the AppImage. Searched open and closed issues and pull requests for "compile cache" and found none covering the npm or archive CLI. This is distinct from the closed lazy-SDK proposals (#8104, #19149): it changes parse cost, not what gets evaluated.

Fix applied or workaround

None applied. Running with NODE_COMPILE_CACHE set in the environment gets the same saving today. I can open a pull request for the bin.ts change once triage confirms the direction. The branch is not written yet; I would add a test next to apps/server/src/compileCache.test.ts that the cache directory is created and that a failing enableCompileCache does not stop startup.

Filed by

No response

  1. bompus(GitHub profile, opens in a new tab) added labelsvia-triage

  2. Note

    Grok responding on behalf of Julius.

    Thanks for the measurements. This is already covered by the open PR #18219: its apps/server/src/cliCompileCache.ts enables Node's compile cache from apps/server/src/bin.ts for the bundled npm CLI and the single-executable build (per-version directory under the T3 home, failures never block startup, AppImage and helper subcommands skipped). I've linked this issue to that PR, so no separate PR is needed. If anything in your numbers isn't addressed once it lands, please comment there.

  3. Update on the pointer above: PR #18219 was closed on 2026-10-21 without being merged, and I found no closing comment on it. So the compile cache for the CLI is no longer covered by an open pull request.

    Checked on current main (b24e8ce2df): apps/server/src/cliCompileCache.ts does not exist, and nothing in apps/server/src enables the compile cache. The only call there is flushCompileCache in serverRuntimeStartup.ts. I searched open and closed pull requests for "compile cache", "compileCache" and "enableCompileCache"; the matches that touch it are #13501 (merged, desktop backend only) and #19256 (closed, AppImage), and none covers the npm or archive CLI. I have not re-measured on current main; the numbers in the description were taken at 4d73e1d5cd.

    Is this still wanted? If yes, I can open a pull request for the bin.ts change described above, with the test next to compileCache.test.ts. If not, this issue can be closed.

  4. maria-rcks closed this

Sign in to join this conversation.