Skip to content

WASM + typescript-go#1677

Open
SamuelMarks wants to merge 2 commits intodsherret:latestfrom
SamuelMarks:wasm-typescript-go
Open

WASM + typescript-go#1677
SamuelMarks wants to merge 2 commits intodsherret:latestfrom
SamuelMarks:wasm-typescript-go

Conversation

@SamuelMarks
Copy link
Copy Markdown

This doesn't need to be merged, more it's just to start a new conversation à la #1656

FWIW: I got my cdd-ts.wasm—Compiler Driven Development (CDD) being a suite of open-source compilers, each written in the language they target, for going to/fro OpenAPI [and more!]—down from 138MB to 106MB. Just by switching from typescript to typescript-go.

Description

This PR fundamentally shifts the compiler architecture of ts-morph by replacing the JavaScript typescript package with Microsoft's typescript-go port compiled to WebAssembly (Wasm).

As detailed in rfcs/RFC-0002-Go-Wasm-Compiler-Migration.md, this brings massive performance improvements (up to 60% faster cold parsing) and slashes the V8 memory overhead by keeping AST structures inside the Wasm linear memory.

Key Changes

  • Wasm Build Pipeline: Added a fully scripted, files-size optimized compilation pipeline utilizing go build and wasm-opt (Binaryen) in scripts/build-wasm.ts.
  • Memory Bridge: Implemented a robust JS-to-Wasm pointer bridge leveraging FinalizationRegistry to synchronize Go's garbage collector with V8.
  • Async Initialization: Replaced synchronous class instantiation with Project.create() to accommodate asynchronous Wasm compilation.
  • Node Proxies: Replaced native AST objects with WasmNode, WasmType, and WasmSymbol proxies that lazily query the Wasm runtime using syscall/js.
  • Testing & Tooling: Configured the existing Mocha test suite to run against the Wasm backend (npm run test:wasm) and added E2E real-world benchmarks.

Notes for Reviewers

  • The Go compiler is currently tracked as a git submodule (packages/compiler-go-source).
  • Wasm initialization gracefully supports Node.js, Deno, and Browser environments, including an inline Base64 fallback for bundlers.
  • Ensure to run npm install and deno task setup to build the new Wasm dependencies locally.

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.

1 participant