Skip to content

Save Node's compiled code at image build, and prefetch the run's files (~45% faster) - #1043

Open
exercism-agent[bot] wants to merge 1 commit into
mainfrom
compile-cache
Open

exercism-agent[bot] wants to merge 1 commit into
mainfrom
compile-cache

Conversation

@exercism-agent

Copy link
Copy Markdown
Contributor

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

This PR makes this project around 45% 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...


What changed

Every run started Node from scratch, and Node compiled Jest's code, Babel and the reporter before it could run a test. This took a large part of each run. The image build now runs the test runner once on a small exercise with NODE_COMPILE_CACHE set. Node saves the compiled code of every module it loads in /opt/test-runner/.node-compile-cache, and each run then loads that code instead of compiling it again.

Node keeps a separate cache for each user ID, so the warm-up runs as appuser. Node writes the cache files readable only by their owner, so the Dockerfile then gives them to root and makes them readable by everyone. Runs only read the cache, and they write nothing new into the container.

On a machine where the image's files aren't in the page cache yet, Node read about 2,900 files one at a time from disk as it needed them, which took several seconds. A second build stage now records the files opened by one run (with strace, which stays out of the final image), and run.sh reads them into the page cache at the start of each run, 8 at a time, in the background. Node then finds most of them already in memory.

The warm-up checks that its run passed, so a broken runner will fail the image build. Students will see no change in results or messages.

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

🤖 Generated with Claude Code

…to the page cache at the start

The image runs the test runner once with NODE_COMPILE_CACHE set, as appuser, so each run loads Jest's compiled code instead of compiling it. A second build stage records the files one run opens (with strace), and run.sh reads them in parallel in the background, so a run on a machine with a cold page cache doesn't wait for each file in turn.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@exercism-agent
exercism-agent Bot requested a review from a team as a code owner November 23, 2026 02:00
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