Repository navigation
Transform files with SWC instead of Babel (~26% faster) - #1041
Draft
exercism-agent[bot] wants to merge 1 commit into
Draft
exercism-agent[bot] wants to merge 1 commit into
exercism-agent[bot] wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
jest.mock(or a related call). Jest needs these calls moved above the imports, and SWC doesn't do that whenjestis imported from@jest/globals. Today onlyfruit-pickerdoes this.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.logat the top level of a solution (outside any function) now appears under a different test. In thetwo-fer/fail/testsfixture, 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 functionbecomesTypeError: (0 , _twofer.twoFer) is not a function. Some stack frames also show different names. Bothtwo-ferfixtures 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.logoutput appears under.This has been tested in production, and has reduced the median run from 2.7s to 2.0s.
🤖 Generated with Claude Code