Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Oct 15, 2025

Summary

Replace TypeScript's tsc with tsgo (TypeScript's new Go-based compiler) for significantly faster type checking in the build system.

Performance Improvement

  • Before (tsc): 5.942s
  • After (tsgo): 0.776s
  • Result: 7.7x faster type checking

Changes

Dependencies

  • Added @typescript/native-preview devDependency (includes platform-specific binaries automatically)

Configuration

  • Updated tsconfig.json to be compatible with TypeScript 7:
    • Removed deprecated baseUrl option
    • Fixed paths to use relative paths (./src/* instead of src/*)

Build System

  • Updated scripts/typecheck.sh to use tsgo with automatic fallback to tsc
  • Updated Makefile dev target to use tsgo in watch mode for faster development feedback

About tsgo

tsgo is Microsoft's Go-based TypeScript compiler that will become the default in TypeScript 7. It provides:

  • Same type checking accuracy as tsc
  • 7-10x performance improvement
  • Native binary execution for better startup time

The implementation uses bun runtime which correctly detects arm64 architecture, and includes fallback to tsc for compatibility.

Testing

Type checking verified locally:

$ time ./scripts/typecheck.sh
[0] bun run node_modules/@typescript/native-preview/bin/tsgo.js --noEmit exited with code 0
[1] bun run node_modules/@typescript/native-preview/bin/tsgo.js --noEmit -p tsconfig.main.json exited with code 0

real    0m0.776s
user    0m2.406s
sys     0m0.638s

Generated with cmux

- Add @typescript/native-preview (tsgo) for TypeScript type checking
- Update tsconfig.json to be compatible with TypeScript 7:
  - Remove deprecated baseUrl option
  - Fix paths to use relative paths (./src/* instead of src/*)
- Update typecheck.sh to use tsgo with fallback to tsc
- Update Makefile dev target to use tsgo in watch mode
- Add platform-specific optional dependencies for all platforms

Performance improvement:
- Before (tsc): 5.942s
- After (tsgo): 0.776s
- **7.7x faster type checking**

tsgo is Microsoft's Go-based TypeScript compiler that provides the
same type checking accuracy as tsc but with significantly better
performance. It will be the default compiler in TypeScript 7.

_Generated with `cmux`_
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

The @typescript/native-preview package already includes platform-specific
packages as its own optionalDependencies, so we don't need to list them
explicitly in our package.json.
Remove scripts/typecheck.sh and move the tsgo/tsc fallback logic
directly into the Makefile typecheck target. The script was only
called from one place, so there's no need for the indirection.
@ammario ammario enabled auto-merge October 15, 2025 01:59
@ammario ammario added this pull request to the merge queue Oct 15, 2025
Merged via the queue into main with commit 96c4390 Oct 15, 2025
7 checks passed
@ammario ammario deleted the tsgo branch October 15, 2025 02:11
ammar-agent added a commit that referenced this pull request Oct 15, 2025
Replaces tsc with tsgo for main process build, reducing compilation time
from 3.489s to 0.178s. Includes comprehensive investigation of tsgo
integration opportunities across the entire build toolchain.

Key findings:
- Main process compilation: 19.6x faster with tsgo
- Type checking: Already optimized (7.7x faster, PR #260)
- Renderer (Vite): Cannot use tsgo due to architectural constraints
- Path aliases: tsc-alias still required (tsgo doesn't resolve them)

See INVESTIGATION.md for complete analysis and benchmarks.
ammar-agent added a commit that referenced this pull request Oct 15, 2025
Replaces tsc with tsgo for main process build, reducing compilation time
from 3.489s to 0.178s. Includes comprehensive investigation of tsgo
integration opportunities across the entire build toolchain.

Key findings:
- Main process compilation: 19.6x faster with tsgo
- Type checking: Already optimized (7.7x faster, PR #260)
- Renderer (Vite): Cannot use tsgo due to architectural constraints
- Path aliases: tsc-alias still required (tsgo doesn't resolve them)

See INVESTIGATION.md for complete analysis and benchmarks.
github-merge-queue bot pushed a commit that referenced this pull request Oct 15, 2025
## 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`_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants