perf(desktop): cache compiled JavaScript between launches #13501
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 6 commits into
main fromrefs/pull/13501/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/desktop/src/compileCache.ts lines 17 to 17OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,17 @@1+// @effect-diagnostics nodeBuiltinImport:off2+// Runs before any Effect runtime exists, so it stays on Node built-ins.3+import * as NodeModule from "node:module";4+import * as NodeOS from "node:os";5+import * as NodePath from "node:path";6+7+// Turns on Node's on-disk V8 code cache for every module loaded after this one,8+// so later launches skip recompiling the large main and server bundles.9+// boot.ts loads it for the main process, and the local backend gets it with10+// `--require`. Linux uses the user's cache dir because /tmp is shared between11+// users; the macOS and Windows temp dirs are already per user.12+const cacheRoot =13+ // oxlint-disable-next-line t3code/no-global-process-runtime -- Loads before any Effect runtime.14+ process.platform === "linux"15+ ? process.env.XDG_CACHE_HOME || NodePath.join(NodeOS.homedir(), ".cache")16+ : NodeOS.tmpdir();17+NodeModule.enableCompileCache(NodePath.join(cacheRoot, "t3code", "compile-cache"));
- @@ -85,3 +85,11 @@8585 onlyBundle: false,8686 },8787 },88+ {89+ // boot.cjs requires the other two at runtime, so all three stay separate files.90+ format: "cjs",91+ outDir: "dist-electron",92+ dts: false,93+ sourcemap: true,94+ outExtensions: () => ({ js: ".cjs" }),95+ entry: ["src/boot.ts", "src/compileCache.ts"],
- apps/desktop/src/compileCache.ts line 9Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,9 @@1+// @effect-diagnostics nodeBuiltinImport:off2+// Runs before any Effect runtime exists, so it stays on Node built-ins.3+import * as NodeModule from "node:module";4+import * as NodeOS from "node:os";5+import * as NodePath from "node:path";6+7+// Turns on Node's on-disk V8 code cache for every module loaded after this one,8+// so later launches skip recompiling the large main and server bundles.9+// Packaged builds only: boot.ts loads it for the main process, and the local
t3dotgg(GitHub profile, opens in a new tab) changed the title
- apps/server/src/compileCache.test.ts line 20Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,20 @@1+// @effect-diagnostics nodeBuiltinImport:off - the test kills a real Node process to prove the cache is on disk.2+import * as NodeChildProcess from "node:child_process";3+import * as NodeFSP from "node:fs/promises";4+import * as NodeOS from "node:os";5+import * as NodePath from "node:path";6+import { assert, it } from "@effect/vitest";7+8+it.each([false, true])(9+ "persists an enabled cache before forced exit (disabled: %s)",10+ async (disabled) => {11+ const directory = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-compile-cache-"));12+ try {13+ const cacheDirectory = NodePath.join(directory, "cache");14+ const child = NodeChildProcess.spawnSync(15+ process.execPath,16+ [17+ "--input-type=module",18+ "--eval",19+ `import * as Effect from ${JSON.stringify(import.meta.resolve("effect/Effect"))};20+const { flushCompileCache } = await import(${JSON.stringify(new URL("./compileCache.ts", import.meta.url).href)});
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed