You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🤖 Lazy-load IpcMain to reduce startup time & lowercase package name (#223)
## Problem
App startup took 6+ seconds for Electron users because `main.ts`
immediately loaded `IpcMain`, which transitively imports the entire AI
SDK stack (`ai`, `@ai-sdk/anthropic`, `ai-tokenizer`, etc.). These are
large modules that weren't needed until the window was created and the
user started interacting.
Additionally, the package was being built as "Cmux" instead of "cmux".
## Solution
### 1. Lazy-load IpcMain
Convert static imports to dynamic imports in `createWindow()`. Config,
IpcMain, and tokenizer modules now load on-demand when the window is
created, not at app startup.
**Before:**
```typescript
import { Config } from './config';
import { IpcMain } from './services/ipcMain';
const config = new Config();
const ipcMain = new IpcMain(config); // Heavy AI SDK loaded immediately
```
**After:**
```typescript
import type { Config } from './config';
import type { IpcMain } from './services/ipcMain';
let config: Config | null = null;
let ipcMain: IpcMain | null = null;
async function createWindow() {
if (!config || !ipcMain) {
// Load only when needed
const [{ Config: ConfigClass }, { IpcMain: IpcMainClass }] = await Promise.all([
import('./config'),
import('./services/ipcMain'),
]);
config = new ConfigClass();
ipcMain = new IpcMainClass(config);
}
// ... create window
}
```
### 2. Lowercase package name
Changed `productName` from "Cmux" to "cmux" in `package.json` build
config.
## Implementation Details
- Changed Config/IpcMain/loadTokenizerModules imports to type-only
imports
- Created module-level variables to cache loaded modules
- Made `createWindow()` async to await dynamic imports
- Moved tokenizer loading to after window creation
- Fixed e2e test userData path (can't use `config.rootDir` before config
loads)
- Added ESLint justification for dynamic imports
## Testing
- ✅ Unit tests pass (379 tests)
- ✅ Type checking passes
- ✅ ESLint passes
_Generated with `cmux`_
0 commit comments