Skip to content

Transform files with esbuild instead of Babel (~28% faster) - #1040

Draft
exercism-agent[bot] wants to merge 1 commit into
mainfrom
esbuild-transformer
Draft

exercism-agent[bot] wants to merge 1 commit into
mainfrom
esbuild-transformer

Conversation

@exercism-agent

@exercism-agent exercism-agent Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Hello 🙂 I'm working with Claude to try and get our tooling faster.

This PR makes this project around 30% faster. I've run it in production to benchmark things in the real world against the most recent few hundred solutions, so I'm confident that it works robustly. However, I've not written the code. I have tried my hardest to get Claude to write sensible messages and comments that explains stuff, but I'd ask for your patience in the fact I'm sending AI code to you. Everything below here is from your friendly neighbourhood LLM...


This is a draft. #1041 is a second draft that does the same job with SWC, so the two can be compared. Only one of them should be merged.

What changed

Jest uses Babel to turn each solution and test file into CommonJS before it runs them. Babel is written in JavaScript. On a test machine, loading its plugins and running them took about 0.6s of a 2.3s run with a warm disk cache, and more with a cold one.

This PR adds jest.transformer.js, which hands most files to esbuild instead. esbuild does the same conversion. It is written in Go and ships as one native binary, so it starts and converts a file in a few milliseconds. esbuild also adds "use strict" to each file, as Babel does. This keeps code such as an assignment to a getter-only property throwing an error.

To keep every test passing or failing exactly as it does today, Babel still handles two kinds of file:

  • Babel compiles files that call jest.mock (or a related call). Jest needs these calls moved above the imports, and esbuild can't do that. Today only fruit-picker does this.
  • Babel compiles any file that esbuild can't compile. If the file has a syntax error, Babel reports the same error as before.

If no file in a run falls into either group, Babel never loads.

Against all 169 example solutions, every test passes or fails as before. Some error messages change slightly, because esbuild names imported modules differently. For example, TypeError: (0 , _twoFer.twoFer) is not a function becomes TypeError: (0 , import_two_fer.twoFer) is not a function. Some stack frames also show different names. The two-fer/fail/empty fixture is updated to match. console.log output still appears under the same test as with Babel.

The image grows from 434 MB to 704 MB.

Compared with #1041, esbuild is about 0.04s per run faster and doesn't change which test console.log output appears under. SWC adds less to the image (608 MB instead of 704 MB).

This has been tested in production, and has reduced the median run from 2.7s to 1.9s.

🤖 Generated with Claude Code

esbuild loads and converts files much faster than Babel. Babel still handles files that call jest.mock and files esbuild can't compile.

Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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