Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented 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 🤖 feat: Replace tsc with tsgo for 7.7x faster type checking #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

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 👍.

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.
Per project guidelines, documentation should not be created in the root.
All investigation findings are captured in the PR description.
Per build reproducibility guidelines, builds should fail fast with clear
errors if dependencies are missing, not silently fall back to different
behavior. Added documentation at top of Makefile about avoiding branches.

Changes:
- Removed if/else fallback in build-main target (now requires tsgo)
- Removed if/else fallback in typecheck target (now requires tsgo)
- Added 'Build Reproducibility' section to Makefile header
- tsgo is in devDependencies, so it's always available after bun install
Reduces duplication of the tsgo binary path across the Makefile.
The path is now defined once at the top and referenced via $(TSGO)
in all targets (dev, build-main, typecheck).

Benefits:
- Single source of truth for tsgo path
- Easier to update if path changes
- More readable target definitions
@ammar-agent ammar-agent force-pushed the investigate-tsgo-build-toolchain branch from 2eeeafd to 3c61331 Compare October 15, 2025 15:25
@ammario ammario added this pull request to the merge queue Oct 15, 2025
Merged via the queue into main with commit 3c1c4fe Oct 15, 2025
7 checks passed
@ammario ammario deleted the investigate-tsgo-build-toolchain branch October 15, 2025 15:46
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