Skip to content

Transform files with SWC instead of Babel (~26% faster) - #1041

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

exercism-agent[bot] wants to merge 1 commit into
mainfrom
swc-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 26% 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. #1040 is a second draft that does the same job with esbuild, 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 SWC (through @swc/jest) instead. SWC produces the same CommonJS as Babel. It is written in Rust and ships as a native library, so it loads and converts a file in a few milliseconds.

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 SWC doesn't do that when jest is imported from @jest/globals. Today only fruit-picker does this.
  • Babel compiles any file that SWC 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. One thing students will see changes: a console.log at the top level of a solution (outside any function) now appears under a different test. In the two-fer/fail/tests fixture, it moves from the second test to the first.

Some error messages also change slightly, because SWC names imported modules differently. For example, TypeError: (0 , _twoFer.twoFer) is not a function becomes TypeError: (0 , _twofer.twoFer) is not a function. Some stack frames also show different names. Both two-fer fixtures are updated to match.

The image grows from 434 MB to 608 MB.

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

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

🤖 Generated with Claude Code

SWC loads and converts files much faster than Babel. Babel still handles files that call jest.mock and files SWC 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