Repository navigation
perf(typecheck): pin Bun as a devDependency and typecheck with it - #30149
Conversation
bun check (Bun 1.4.3, TypeScript 7.0.2 parity, already used by CI) checks the node project in ~29 CPU-s / ~2 GB peak vs tsc's ~98 CPU-s / ~16.6 GB. tsc's incremental cache rarely helps agents: noEmit builds store no declaration signatures, so the first edit to any file after a cold check re-checks every transitive importer (a comment in src/shared/constants.ts re-checks all 18k files). pnpm tc / tc:node / tc:web / tc:cli now pick the Bun from config/.bun-version when it is on PATH and fall back to tsc with a one-line hint otherwise; --compiler=native forces tsc. The pinned-Bun probe is shared with the localization extraction check.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 16 minutes. View limit details
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
🧹 Nitpick comments: 1
config/scripts/run-typecheck-projects-in-parallel.test.mjs: 1
148-164: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winThe repository tests do not cover the CLI handoff from automatic compiler selection to the spawned Bun process. The selector test checks only the returned
bunExecutable, while the runner tests do not reach Bun spawning or use the native compiler path. A localized integration assertion for the CLI-to-spawn boundary would protect this new behavior, but the evidence does not show a current production failure.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2f3c892a-4e0a-4d83-98e2-3220712acb01
📒 Files selected for processing: 6
.github/CONTRIBUTING.mdconfig/scripts/pinned-bun-executable.mjsconfig/scripts/run-typecheck-projects-in-parallel.mjsconfig/scripts/run-typecheck-projects-in-parallel.test.mjsconfig/scripts/verify-localization-extraction.mjspackage.json
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
The PATH probe left anyone without the exact pinned Bun (including a 1.4.2 global) on tsc's expensive path. [email protected] is now a devDependency, its postinstall is allowed, and pnpm tc / typecheck:ci run that binary. A missing binary is an error pointing at pnpm install rather than a silent fallback; --compiler=native still selects tsc. A test keeps the devDependency equal to config/.bun-version.
--ignore-scripts leaves node_modules/.bin/bun as bun's postinstall stub, so the typecheck runner found no binary and any pnpm-run script calling bun would hit the stub before setup-bun's copy. pnpm rebuild bun runs only that allowed build.
ELI5
pnpm tcis the typecheck every agent runs over and over. With TypeScript's native compiler (tsc), one check of the node project can take about 16 GB of RAM and 100 CPU-seconds, so a few agents checking at once swamp the machine. CI already uses Bun'sbun check, which reports the same errors for a fraction of that. This PR pins Bun as a normal devDependency, so everypnpm installgets the exact version, and makespnpm tcuse it.What Changed
pnpm tcandtc:node/tc:web/tc:clialways rantsc --noEmitwith its incremental cache. Bun was something each developer installed by hand to matchconfig/.bun-version. Drift was common: the machine this was measured on had 1.4.2.[email protected]is an exact devDependency, andpnpm-workspace.yamlallows its postinstall step, which links the platform binary.pnpm tcand by CI'stypecheck:ci, runs that binary.--ignore-scripts), the check fails and says to runpnpm install, instead of quietly running the expensive check.--compiler=nativestill selectstsc.config/.bun-version, which CI'ssetup-bunstill reads.config/scripts/pinned-bun-executable.mjs.Measured on a 16-core M-series Mac:
pnpm tcWhy
The incremental cache was the reason to keep
tsclocally, but in practice it rarely saves the work.noEmitbuilds, sotscnever records each file's declaration signature (its public API). The cache stores the file's content hash in its place: 3 of 18,095 files had real signatures.src/shared/constants.tsre-checked the whole node project (104 CPU-s), the same as a cold run.So the realistic cost of a
tscrun is close to the cold row, while Bun's cost is flat and its memory use is about an eighth.Why a devDependency rather than asking developers to install Bun: this is how JS repos usually pin binary tools (esbuild, turbo, biome). The lockfile fixes the version per worktree, the pnpm store dedupes the ~67 MB binary across worktrees, and
pnpm runputs it on PATH for the other scripts that callbun. The PATH-probe version that came before this left every developer whose Bun didn't match on the expensive path.Alternatives considered:
tscrecords real signatures. This makes comment- and body-only edits cheap. But API edits still re-check the whole chain at 16 GB, and it writes about 70 MB of.d.tsfiles per project per worktree.assumeChangesOnlyAffectDirectDependencies: can miss errors.--checkers: 4 → 2 saves only 11% CPU and 3 GB.Linked Issue
N/A (maintainer)
Visual Proof
N/A: developer tooling only; no app behaviour changes.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
With only Bun 1.4.2 on PATH:
pnpm tc,tc:webandtypecheck:ciall check with the 1.4.3 devDependency.Injecting a type error and an unused local gives identical diagnostics and exit 1 from both Bun and
tsc.verify:localization-extractionstill passes.Runner tests cover: Bun as the default,
--projectfiltering, a missing Bun failing loudly,--compiler=nativenever probing for Bun, and the devDependency matchingconfig/.bun-version.Review
Agent skill upstream boundary
Notes
bunnpm package ships binaries for macOS, Linux (glibc and musl) and Windows on x64 and arm64.bun checkis cross-platform.--compiler=bunwith explicit concurrency and thread counts.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)