Files
iptvnator/apps/electron-backend/src/main.entry.ts
T
4grayandClaude Fable 5.1 587e19541f perf(electron): compile the main-process bundle from a V8 code cache (#1696)
main.js is now a small entry that enables Node's on-disk V8 compile cache under userData/v8-compile-cache and then requires the application bundle main.app.js. Warm launches reach app.whenReady about 13 ms sooner at the median; IPTVNATOR_DISABLE_COMPILE_CACHE=1 turns it off and IPTVNATOR_COMPILE_CACHE_DIR relocates it.

Packaging now ships main.app.js explicitly and verify:package-layout requires the main-process entry files in app.asar, because nx-electron copies the backend through an allowlist. The Xtream benchmark build identity hashes both the launcher and the bundle.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-26 19:19:30 +02:00

36 lines
1.4 KiB
TypeScript

/**
* Process entry of the Electron main process. It becomes
* `dist/apps/electron-backend/main.js`: the file Electron, `nx serve`, the E2E
* fixtures and the packaged app launch.
*
* It enables the V8 compile cache and only then requires the application
* bundle, `main.app.js` (built from `main.ts`). V8 writes a code cache for
* the script being compiled, so a call inside the bundle would leave the
* bundle itself uncached; only this small file pays the uncached compile.
* Keep it free of imports beyond `electron`, Node built-ins and the guard
* helper: anything imported here is compiled before the cache is on.
*/
import { app } from 'electron';
import * as nodeModule from 'node:module';
import {
enableStartupCompileCache,
publishCompileCacheOutcome,
type CompileCacheModule,
} from './app/services/compile-cache';
declare const __non_webpack_require__: NodeJS.Require;
publishCompileCacheOutcome(
enableStartupCompileCache({
module: nodeModule as CompileCacheModule,
// Read before main.ts calls app.setName(), deliberately: renaming
// here would move every path derived from the app name, including
// the settings store's, for existing Linux profiles. On macOS and
// Windows the directory is the same either way.
userDataPath: () => app.getPath('userData'),
})
);
// Resolved next to this file at run time; webpack must not inline it.
__non_webpack_require__('./main.app.js');