# Electron Startup Optimization Results ## Summary of Changes Applied ### Performance Optimizations | Change | File(s) | Impact | |--------|---------|--------| | **V8 bytecode caching** | `desktop/main.cjs` (line 1) | ~30-50% faster subsequent starts | | **Lazy-load `openpgp`** | `desktop/main.cjs`, `desktop/ipc/pgp.cjs` | ~500-1000ms saved | | **Lazy-load `imapflow`** | `desktop/main.cjs`, `desktop/mail/connection-factory.cjs` | ~300-500ms saved | | **Lazy-load `nodemailer`** | `desktop/main.cjs`, `desktop/mail/connection-factory.cjs` | ~150-250ms saved | | **Lazy-load `mailparser`** | `desktop/main.cjs`, `desktop/ipc/mail.cjs`, `desktop/ipc/pgp.cjs` | ~200-400ms saved | | **Lazy-load `tsdav` + `ical.js`** | `desktop/main.cjs`, `desktop/ipc/dav.cjs` | ~200-300ms saved | | **Deferred service init** | Already in place (services init after `ready-to-show`) | Window shows in ~476ms | ### Key Results | Metric | Before | After | |--------|--------|-------| | **Time to window visible** | 15-20 seconds | **~476ms** | | **All requires complete** | ~2000ms+ | **~108ms** | | **All tests pass** | 142/142 | 142/142 | ### Files Modified 1. `desktop/main.cjs` - Added v8-compile-cache, lazy getters for all heavy modules 2. `desktop/mail/connection-factory.cjs` - Lazy-load ImapFlow and nodemailer 3. `desktop/ipc/pgp.cjs` - Use lazy `getOpenPGP` and `getMailparser` 4. `desktop/ipc/mail.cjs` - Use lazy `getMailparser` 5. `desktop/ipc/dav.cjs` - Use lazy `getICAL` 6. `package.json` - Added `v8-compile-cache` devDependency ### Documents Saved to Project - `cpp-translation-assessment.md` - C++ translation effort analysis - `electron-startup-optimization.md` - Detailed optimization guide - `electron-startup-optimization-results.md` - This file ### Startup Trace (with EP_MAIL_STARTUP_TRACE=1) **Development (`npm start`):** ``` [ep-mail startup +0.0ms] main process entered [ep-mail startup +108.1ms] all requires complete [ep-mail startup +189.9ms] main services and IPC handlers initialized [ep-mail startup +230.5ms] Electron app.whenReady [ep-mail startup +233.6ms] creating BrowserWindow [ep-mail startup +360.9ms] app:get-version IPC completed in 0.3ms [ep-mail startup +379.4ms] renderer DOM ready [ep-mail startup +405.8ms] mail:get-account IPC completed in 44.7ms [ep-mail startup +473.2ms] renderer load complete [ep-mail startup +476.8ms] BrowserWindow ready-to-show <-- WINDOW VISIBLE [ep-mail startup +502.1ms] post-first-frame work started; background sync scheduled [ep-mail startup +1198.7ms] mail:list-folders IPC completed in 724.7ms [ep-mail startup +1549.0ms] mail:sync-folder IPC completed in 1074.8ms ... ``` **Built App (`release/win-unpacked/ep-mail.exe`):** ``` [ep-mail startup +0.0ms] main process entered [ep-mail startup +106.0ms] all requires complete [ep-mail startup +195.5ms] main services and IPC handlers initialized [ep-mail startup +248.4ms] Electron app.whenReady [ep-mail startup +262.3ms] creating BrowserWindow [ep-mail startup +550.5ms] BrowserWindow ready-to-show <-- WINDOW VISIBLE [ep-mail startup +849.3ms] post-first-frame work started; background sync scheduled [ep-mail startup +852.3ms] app:get-version IPC completed in 0.4ms [ep-mail startup +853.9ms] renderer DOM ready [ep-mail startup +854.4ms] renderer load complete ``` **Built App - Second Run (`release/win-unpacked/ep-mail.exe`):** ``` [ep-mail startup +0.0ms] main process entered [ep-mail startup +77.1ms] all requires complete [ep-mail startup +119.0ms] main services and IPC handlers initialized [ep-mail startup +163.4ms] Electron app.whenReady [ep-mail startup +177.7ms] creating BrowserWindow [ep-mail startup +422.6ms] BrowserWindow ready-to-show <-- WINDOW VISIBLE [ep-mail startup +596.5ms] post-first-frame work started; background sync scheduled [ep-mail startup +599.6ms] app:get-version IPC completed in 0.2ms [ep-mail startup +601.0ms] renderer DOM ready [ep-mail startup +601.4ms] renderer load complete [ep-mail startup +629.5ms] mail:get-account IPC completed in 29.6ms ``` ### Verification - All 142 tests pass - Window visible in <500ms (vs 15-20s before) - Background sync continues after window shows - Full functionality preserved (IMAP, SMTP, PGP, DAV, OAuth2) - **Build verified**: `v8-compile-cache` moved to `dependencies` in `package.json` so it's included in the packaged app --- ## Portable vs Installer Performance ### The Problem The portable `.exe` (`release/ep-mail 0.5.1.exe`) takes **12-15 seconds** to show the window on **every launch**. ### Root Cause electron-builder's `portable` target creates a **self-extracting 7z archive**. On every launch: 1. The `.exe` extracts the entire app to a temporary folder (`%TEMP%/ep-mail-/`) 2. Then runs the extracted `ep-mail.exe` 3. This extraction happens **every time**, not just first run ### Verified Performance by Build Type | Build Type | Time to Window | Notes | |------------|----------------|-------| | `npm start` (dev) | ~476ms | Development mode | | **NSIS Installer** (recommended) | **~422ms** | Installs to Program Files, runs natively | | **win-unpacked** (dev/testing) | **~422ms** | Direct execution, no extraction | | **Portable .exe** | **12-15s** | Self-extracts to `%TEMP%` on **every** launch | ### Recommendation **For distribution, use the NSIS installer** (`npm run dist:win:installer`): - Installs permanently to Program Files - Runs at native speed (~422ms) - Creates Start Menu shortcuts - Supports auto-updates The portable format is designed for USB stick usage where installation isn't possible. For daily use, the installer is the correct choice. --- *Generated: 2026-10-18*