perf(electron): load the main-process startup wiring after the window starts loading (#1702)

Registering IPC handlers costs 0.4 ms; evaluating the modules behind them (axios, drizzle-orm, better-sqlite3, electron-updater, fix-path) before the window could load was the real cost. main.ts now keeps only the pre-paint wiring and loads the rest as the deferred-events.js chunk inside the main window's did-start-loading listener, where the import and its registrations complete before any renderer invoke can arrive.

Interleaved A/B on the performance build: app.whenReady 323 -> 265 ms, did-finish-load 499 -> 447 ms; J1 journey spawnToDidFinishLoad ~405 -> ~365 ms with identical counters. Packaging ships the chunk explicitly, verify:package-layout requires it, and the benchmark build identity hashes it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
4grayandClaude Fable 5.1 authored and GitHub committed 2026-09-26 21:51:19 +02:00
1 parent 497b6076fa
commit e39c854a41
13 files changed
+565 -138

No files matched your search

@@ -474,13 +474,15 @@ function verifyPackagedPackageMetadata(resourceDir, errors) {
/**
* The main-process entry is split: `main.js` enables the V8 compile cache and
* requires `main.app.js`, the application bundle. nx-electron packages the
* requires `main.app.js`, the application bundle, which loads the
* `deferred-events.js` chunk once the window starts loading. nx-electron packages the
* backend through an allowlist, so a missing bundle only surfaces as an
* uncaught "Cannot find module" at launch; fail the layout check instead.
*/
const REQUIRED_MAIN_PROCESS_ENTRIES = [
'/electron-backend/main.js',
'/electron-backend/main.app.js',
'/electron-backend/deferred-events.js',
'/electron-backend/main.preload.js',
];