Skip to content

spike: evaluate Bun for scripts, transpilation, and test running #1247

Closed as not planned

Description

@o-alexandrov

Goal

Spike, not a migration. Measure whether moving parts of Octane's toolchain to Bun is worth doing, and produce numbers plus a go/no-go per area. Nothing here should be merged as a migration until the measurements exist.

Three separable areas, in increasing order of risk:

  1. Node scripts to Bun (low risk)
  2. TypeScript transpilation to Bun (medium)
  3. Vitest/Playwright to bun test + Bun.WebView (high, likely a partial at best)

Why this is worth measuring

CI wall-clock is the motivation, so it is worth being precise about where time actually goes. From a recent heavy integration (package builds, eval corpus, runtime loaders, Astro) run, total 89s, the slowest items were:

  • rspeedy-plugin packed-consumer build: 16.0s
  • rspeedy-plugin demo (dev command + bundle): 9.6s
  • vite-plugin client-reference chunk mapping: 7.8s
  • rspeedy-plugin-browser web-host: 5.1s

Those are esbuild/Rspack/Vite builds and browser launches, not test-runner overhead. The test shard (Node 24, 1-4/4) jobs finished at 10m38s / 10m33s / 8m38s / 8m35s, so there is also ~2min of idle tail from shard imbalance.

Hypothesis to falsify: runner startup overhead is a small fraction of Octane's CI time, so a runner swap yields far less than rebalancing shards or reusing builds. The spike should either confirm this and close the door, or produce numbers that contradict it.

Current surface (measured on main @ 27abffc26)

Test/runner coupling:

Metric Count
vitest.config.js 9,426 lines
Vitest projects 393
Projects using the octane() Vite plugin 278
resolve.alias blocks 264
globalSetup hooks 72
testExecution groups (react-parity sharding) 220
Test files importing vitest 1,961
.tsrx source files 2,533
Files using vi.fn/vi.spyOn 518
Files using vi.mock 44
Files using fake timers 43
Files using expect.poll 24
Files using snapshots 22
Vitest browser-mode projects 2
Patched Vitest packages 2 (@vitest/browser, @vitest/mocker)
Environments 211 jsdom, 176 node, 2 happy-dom

Runtime/transpile surface:

  • engines.node: >=22.22.2; CI pins node-version: 24; packageManager: [email protected]
  • 66 of 102 root scripts invoke node or node --test directly
  • 67 scripts/*.mjs, of which 26 contain node:test suites
  • Transpile-adjacent deps: esbuild, typescript, @typescript/native-preview, @babel/core, @rolldown/plugin-babel, babel-plugin-react-compiler, babel-plugin-inferno, @tsrx/typescript-plugin, vite, vitest

Area 1 — Node scripts to Bun (low risk, start here)

The 67 scripts/*.mjs are plain ESM with few dependencies. scripts/reconcile-github-releases.mjs needs only semver. The 26 node:test suites are the interesting part: Bun implements a node:test shim, but coverage is not total.

Tasks:

  • Run all 26 node --test suites under bun --bun node --test and under bun test, record pass/fail/skip deltas
  • Time node scripts/<x>.mjs vs bun scripts/<x>.mjs for the 10 most-invoked scripts
  • Note any node: API gaps hit (worker_threads, vm, async_hooks, perf hooks)

Exit criteria: a table of per-script timings and a list of incompatibilities. This area can likely land independently of the others.

Area 2 — TypeScript transpilation to Bun (medium risk)

The blocker is that .tsrx is not TypeScript. 2,533 .tsrx files are compiled by Octane's own compiler through its Vite plugin (packages/octane/src/compiler/vite.js), used by 278 of 393 projects. Bun's transpiler has no hook for a custom language, so bun build/bun test cannot consume .tsrx without a plugin that shells into the Octane compiler.

The differential tests raise the bar further: tests/differential/_setup.ts files compile each fixture twice, once for Octane and once with octane → react rewritten, so real React acts as a byte-level oracle. That dual-compile is the project's core correctness evidence and must not silently degrade.

Tasks:

  • Prototype a Bun plugin (Bun.plugin / bunfig preload) that routes .tsrx through the existing compiler, and see whether bun build can produce a working artifact for one small package
  • Compare esbuild vs Bun.build on one package's build step, wall-clock and output size
  • Assess whether @typescript/native-preview (already a dep) overlaps or competes with this
  • Explicitly evaluate: is bun --bun in front of the existing Vite builds (example apps, website) a cheaper win than replacing the transpiler? This is the same trick already used elsewhere and carries no test-correctness risk.

Exit criteria: either a working .tsrx Bun plugin with a build-time comparison, or a written statement of exactly what blocks it.

Area 3 — Vitest/Playwright to bun test + Bun.WebView (high risk)

Expect a partial result. Known blockers, each needs a decision rather than a workaround:

  • No Vite plugin pipeline in bun test. 278 projects depend on octane() running as a Vite plugin. This is the same blocker as Area 2 and gates almost everything.
  • expect.poll has no Bun equivalent (24 files).
  • Module mocking differs. 518 files use vi.fn/vi.spyOn, 44 use vi.mock, 43 use fake timers. Bun's mock/jest.fn are close but not identical.
  • No per-project DOM environment. 211 jsdom + 2 happy-dom projects switch via config; Bun needs a preload registering a global DOM instead.
  • Browser mode has no analogue. 2 projects run through @vitest/browser-playwright, plus 2 local patches.
  • Bun.WebView is documented as experimental and cannot replace Playwright for Octane's cases:
    • No request interception. packages/vite-plugin-octane/tests/production.test.ts uses page.route() to hold a module in flight and prove early SSR input survives; that gating is the test.
    • webkit backend is macOS-only and throws elsewhere. CI is Ubuntu, so every WebView run there is Chrome, losing the WebKit coverage that surfaced test(vite-plugin): fix webkit operation-completion poll flake #1240.
    • On Linux it still drives an installed Chrome over CDP, so the saving is the Playwright browser download, not the browser launch.

Where WebView plausibly does fit: simple load-and-evaluate probes such as packages/syntax-highlighter/tests/browser/rendering.browser.test.ts (waitForFunction(() => Boolean(window.__syntaxHighlighterBrowser))), and the colorful/popper browser suites.

Tasks:

  • Port one environment: 'node' project with no octane() plugin and no .tsrx fixtures to bun test; report wall-clock and any API gaps
  • Port one simple browser probe to Bun.WebView; measure against the Playwright equivalent on Linux, not just macOS
  • Decide whether a mixed world (Bun for leaf unit projects, Vitest for compiler/differential/browser) is acceptable, or whether split tooling costs more than it saves

Exit criteria: two ported projects with numbers, plus a recommendation on partial adoption. Do not convert 1,961 files in this spike.

Non-goals

  • Replacing pnpm. The workspace uses a catalog and patchedDependencies; package management is a separate discussion.
  • Landing any migration. This issue produces measurements and a recommendation only.
  • Dropping WebKit coverage to make WebView viable.

Deliverable

A comment on this issue with:

  1. A timing table per area (before/after, same hardware)
  2. An explicit go/no-go per area
  3. For any no-go, the specific blocker
  4. If total projected CI saving is under ~10%, say so plainly and recommend shard rebalancing and build reuse instead

Prior context

Timings and the WebKit interception dependency come from investigating the production.test.ts WebKit flake fixed in #1240.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions