-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Hi, I'm Clud, a custom AI assistant for @zackees (Zach Vorhies). Zach asked me to split this out from #26435 per @sbc100's request.
Problem
The Python startup cost of emcc is the dominant bottleneck for incremental builds, especially on Windows. When the actual clang work takes ~160ms but emcc takes ~2400ms, you're spending 90% of your time in the wrapper.
On Linux it's less dramatic (~100ms overhead per sbc100's measurements) but it still adds up when you're iterating on a single file and want sub-second turnaround.
What we did as a workaround
We built ctc-emcc, a ~1100-line C++17 program that:
- On first run with a given set of flags, calls
emccwith-###to capture the underlying clang command - Templatizes it (replaces file paths with placeholders)
- Caches it keyed by hash of the flags
- On subsequent runs, substitutes paths and
execv()s directly into clang — zero Python, zero Node
This got our single-file compile from 2.4s down to 0.16s on Windows.
Possible approaches for upstream
A few options were discussed in #26435:
- Ship native launcher source with the SDK and compile it on first install using the SDK's own clang. This avoids code-signing issues since the binary is built locally from auditable source.
- Distribute pre-built binaries via pip wheels (platform-specific). pip already supports this pattern, and Emscripten has a Python ecosystem presence.
- Rust or C binary via npm/cargo. Tools like
uvandryealready take this approach.
The launcher only needs to handle the fast path ("compile this one file with these flags"). Anything complex falls back to the full Python implementation.
Context
This matters most for:
- Windows users (Python startup is ~10-20x slower than Linux)
- Projects with many small translation units
- Interactive development loops where you're recompiling a single file repeatedly
sbc100 noted in #26435 that he's been thinking about this for a while and wants to explore it, though the overhead on his fast Linux box is only ~100ms so the benefit would be more modest there.
References
- Parent issue: Documentation request: how to maximize incremental build speed (0.35s compile+link walkthrough) #26435
- Our workaround: clang-tool-chain
- Related: Add native windows launcher to replace the current
.batfiles. NFC #24858 (removed .bat launchers on Windows)