Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(desktop): AppImage launches reuse a compile cache shipped in the image #19256

Closedayagmar(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/19256/headopened View on GitHub

Problem

The Linux AppImage recompiles the 5 MB main bundle and the 14 MB server bundle on every launch. compileCache.ts skips Node's compile cache under APPIMAGE because the image mounts at a new /tmp/.mount_* path each time and Node keys cache entries by absolute path (#13501). The .deb and AUR installs have a fixed path and already get the cache. Launch the AppImage with NODE_DEBUG_NATIVE=COMPILE_CACHE and no cache activity is logged in either process.

Change

Warm a portable compile cache at build time and ship it in the image at resources/compile-cache. Portable entries are keyed relative to the cache directory, so they hit from any mount path, and the read-only image just means misses are compiled again. Nothing smaller works: Node's cache format is internal, and the server's chunks only load at runtime, so the entries have to come from running the packaged app once.

  • compileCache.ts: under APPIMAGE, use the shipped cache in portable mode.
  • scripts/desktop-compile-cache-hook.ts: Linux afterPack hook. Compiles main.cjs and runs the packaged backend to readiness with an allowlisted environment, analytics off and a scratch home, then fixes permissions. It only runs in release packaging; ci.yml never builds the Linux artifact.
  • Node 24 scopes the cache directory by uid, so the hook ships uid 1000. Other uids, and anyone who changes V8 flags through NODE_OPTIONS, get what every AppImage user gets today: no cache. Node 26 drops the uid for portable caches (nodejs/node#65293); once Electron ships it, the hook passes the directory through as is and every uid hits.

The .deb and the AUR package are built from the same unpacked directory and carry the 12 MB directory unused. The AppImage grows from 163.1 to 167.2 MB.

Scope and approval

No prior issue or discussion. This is a focused performance fix with no product behavior change: the app does the same work, it just stops recompiling two bundles on every launch. The problem is established by the measurements below rather than a bug report.

Verification

Ryzen 9 9950X3D, Arch, Electron 44.4.5. Two locally built AppImages, 10 launches each after a warm-up launch, median ms from process spawn.

mainthis PR
Backend ready, main window created21221939
Renderer dom-ready21822011
Headless serve to HTTP ready952822

The same image with NODE_DISABLE_COMPILE_CACHE=1 reaches backend ready at 2064 ms, so about 125 ms of the gap is the cache and the rest is run-to-run drift between two builds. Inside the mounted image, NODE_DEBUG_NATIVE=COMPILE_CACHE shows main.cjs accepted in the Electron main process and 120 entries accepted, 0 rejected, in the backend.

  • vp test run apps/desktop/scripts/main-process-bundle.test.mjs scripts/build-desktop-artifact.test.ts: 81 passed. The new test warms a cache at one mount path, then launches from a second, read-only mount path and asserts Node reports the main.cjs entry accepted with nothing written.
  • Lint, format and the scripts typecheck are clean on the changed files.
  • vp run dist:desktop:linux on this head builds the AppImage and .deb; the hook warmed 127 entries. Warming the extracted image as uid 0 inside unshare -rn with only loopback up, then reading it as uid 1000, gives the same 120 accepted entries, which is the CI-to-user path.
  • Not verified: a release-runner build (the arm64 job has not run this hook) and a user whose uid is not 1000, who should see today's behavior.
Method and repro

Milestones come from desktop.trace.ndjson (end of desktop.window.handleBackendReady) and renderer-history.ndjson (dom-ready for the main surface) under a scratch T3CODE_HOME, timed from the spawn of the AppImage. Spread: backend ready 2031 to 2501 on main, 1897 to 2080 on this PR. One interleaved A/B pair afterwards: 2148 to 2000.

vp run dist:desktop:linux
T3CODE_HOME=/tmp/t3code-bench ./release/T3-Code-*-x86_64.AppImage
# hits from inside the image:
./release/T3-Code-*-x86_64.AppImage --appimage-mount   # prints <mount>
APPIMAGE=$PWD/release/T3-Code-*-x86_64.AppImage ELECTRON_RUN_AS_NODE=1 NODE_DEBUG_NATIVE=COMPILE_CACHE \
  <mount>/t3code --require <mount>/resources/app.asar/apps/desktop/dist-electron/compileCache.cjs \
  <mount>/resources/app.asar/apps/server/dist/bin.mjs --help 2>&1 | grep -c "was accepted"

The V8 cache tag hashes version and flags, not CPU features (v8/src/api/api.cc, CachedDataVersionTag), so runner-warmed entries are valid on user machines. The hook takes about 3 s and fails the build if the backend never reaches readiness or writes nothing.

Written by Claude Fable 5.1 in Claude Code, reviewed by Claude Opus 5.5.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. @@ -0,0 +160,21 @@
      160+ args: ReadonlyArray<string>,
      161+ env: NodeJS.ProcessEnv,
      162+ cacheDir: string,
      163+ stderrPath: string,
      164+): Promise<void> {
      165+ const before = await countEntries(cacheDir);
      166+ const port = await freePort();
      167+ const warm = spawnWarm(
      168+ electron,
      169+ [...args, "--mode", "desktop", "--port", String(port), "--host", "127.0.0.1", "--no-browser"],
      170+ env,
      171+ stderrPath,
      172+ );
      173+ const fail = async (reason: string): Promise<never> => {
      174+ const exit = await stop(warm);
      175+ throw new Error(`${reason} (backend exit: ${exit})\n${await stderrTail(warm)}`);
      176+ };
      177+
      178+ const readyDeadline = Date.now() + READINESS_TIMEOUT_MS;
      179+ let ready = false;
      180+ while (!ready && warm.child.exitCode === null && Date.now() < readyDeadline) {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium scripts/desktop-compile-cache-hook.ts:180

      A backend killed by a signal before readiness is treated as still running, so the hook keeps probing for up to 120 seconds and reports a readiness timeout instead of detecting the termination promptly. exitCode remains null after signal termination; also check warm.child.signalCode in the loop condition.

      Suggested change
      180- while (!ready && warm.child.exitCode === null && Date.now() < readyDeadline) {
      180+ while (!ready && warm.child.exitCode === null && warm.child.signalCode === null && Date.now() < readyDeadline) {
      🤖 Copy this AI Prompt to have your agent fix this:
      In file @scripts/desktop-compile-cache-hook.ts around line 180:
      
      A backend killed by a signal before readiness is treated as still running, so the hook keeps probing for up to 120 seconds and reports a readiness timeout instead of detecting the termination promptly. `exitCode` remains `null` after signal termination; also check `warm.child.signalCode` in the loop condition.

      Fixed in 90d7dac27: the readiness loop now also stops on signalCode, so a backend killed before readiness fails the build immediately instead of after the 120 s probe window. Same push drops two of the four diagnostic suppressions by using timers/promises and performance.now().

      Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    3. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR adds a substantial Linux packaging hook that executes the packaged application during builds and changes AppImage startup to use a shipped compile cache. It also adds multiple static-analysis suppression directives and has an unresolved Medium-severity failure-path finding in the warm-up process.

      Not approved because:

      • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).

Sign in to join this conversation.