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
🤖 perf: Use tsgo for main process compilation (19.6x faster) (#264)
## Summary
Replaces `tsc` with `tsgo` for main process compilation, achieving a
**19.6x speedup** (3.489s → 0.178s). Completes investigation of tsgo
integration opportunities across the entire build toolchain.
## Performance Impact
**Main process build:**
- Before: 3.489s with tsc
- After: 0.178s with tsgo
- **Speedup: 19.6x**
**Type checking (already optimized in PR #260):**
- Before: 5.942s with tsc
- After: 0.776s with tsgo
- **Speedup: 7.7x**
**Full build:**
- Before: ~26s total
- After: ~22.5s total (~13% faster)
## Regression Risk ⚠️
**Medium risk** - Changing the compiler from tsc to tsgo for production
builds:
1. **TypeScript 7 preview**: `@typescript/native-preview` is pre-release
software (v7.0.0-dev)
2. **Different code generator**: While type checking is identical, the
emitted JavaScript may have subtle differences
3. **Platform-specific binaries**: Relies on Go-based native binaries
for darwin/linux/win32 across x64/arm64
4. **Path alias resolution**: Still requires `tsc-alias` post-processing
(tsgo doesn't resolve `@/` imports)
**Mitigation:**
- CI tests run on both macOS and Linux
- Integration tests verify IPC communication paths
- E2E tests verify full application behavior
- Build is deterministic (no conditional branches)
**Rollback plan:** If issues arise, revert to `tsc` by changing one line
in Makefile (line 77).
## Changes
- **Updated `Makefile` build-main target**: Uses tsgo directly, no
fallback branches
- **Updated `Makefile` typecheck target**: Removed tsc fallback (already
had branch from PR #260)
- **Added build reproducibility guidelines**: Documents why branches are
avoided in build targets
- **Requires tsgo**: Builds fail fast if tsgo missing (in
devDependencies, always available)
## Investigation Findings
Analyzed every component of the build toolchain to maximize tsgo usage:
| Component | Current Tool | Can Use tsgo? | Status |
|-----------|--------------|---------------|--------|
| Main process build | tsc | ✅ Yes | ✅ Implemented |
| Renderer build | Vite+esbuild | ❌ No | N/A (Vite architecture) |
| Preload build | bun | ❌ No | N/A (already fast) |
| Type checking | tsgo | ✅ Yes | ✅ Done (PR #260) |
| Dev watch (main) | tsgo -w | ✅ Yes | ✅ Done (PR #260) |
**Key findings:**
1. **Path alias resolution**: tsgo doesn't resolve `@/` imports, so
`tsc-alias` still required (~0.7s overhead, acceptable)
2. **Vite can't use tsgo**: Different compilation model (esbuild + HMR +
bundling)
3. **Main build time dominated by Vite**: ~21s for renderer vs ~0.2s for
main process
**Conclusion:** We've maximized tsgo usage. The remaining build time
(~21s Vite renderer compilation) cannot be optimized with tsgo due to
architectural constraints.
## Build Reproducibility
Removed all conditional branches (if/else fallbacks) from build targets.
Builds now fail fast with clear errors if dependencies are missing,
rather than silently using different compilers.
Added to Makefile header:
> **AVOID CONDITIONAL BRANCHES (if/else) IN BUILD TARGETS AT ALL
COSTS.**
> Branches reduce reproducibility - builds should fail fast with clear
errors if dependencies are missing, not silently fall back to different
behavior.
## Testing
- ✅ Full build succeeds: `make build`
- ✅ Type checking works: `make typecheck`
- ✅ No unresolved `@/` imports in compiled output
- ✅ Dev watch works: `make dev`
- ⏳ CI checks (static, integration, e2e) pending
_Generated with `cmux`_
dev: node_modules/.installed build-main ## Start development server (Vite + tsgo watcher for 10x faster type checking)
58
66
@bun x concurrently -k \
59
-
"bun x concurrently \"bun run node_modules/@typescript/native-preview/bin/tsgo.js -w -p tsconfig.main.json\"\"bun x tsc-alias -w -p tsconfig.main.json\""\
67
+
"bun x concurrently \"$(TSGO) -w -p tsconfig.main.json\"\"bun x tsc-alias -w -p tsconfig.main.json\""\
60
68
"vite"
61
69
62
70
start: node_modules/.installed build-main build-preload build-static ## Build and start Electron app
@@ -69,7 +77,7 @@ build-main: node_modules/.installed dist/main.js ## Build main process
0 commit comments