Repository navigation
Run the type tests in the same process as the type check - #107
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
This was referenced Nov 24, 2026
iHiD
force-pushed
the
faster-type-tests
branch
from
November 24, 2026 11:32
4b52ff8 to
6fc74e0
Compare
This was referenced Nov 24, 2026
The tstyche command took about 3 seconds for lasagna's type tests. It loaded its own copy of TypeScript, then parsed and bound the standard library and the Node types twice: once for tsconfig.json, which excludes the type tests, and once for a default project for the test file. bin/compile.cjs now loads TypeScript through tstyche, and after the type check runs tstyche in the same process on a program that reuses the type check's parsed files. The type tests now add about 0.3 seconds. They use the compiler options from tsconfig.json, as they do when students run them locally. Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
iHiD
force-pushed
the
faster-type-tests
branch
from
November 24, 2026 13:27
6fc74e0 to
77a2a6f
Compare
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 draft makes runs of exercises with type tests about twice as fast, so an exercise can have both runtime tests and tstyche type tests without a slow run. It follows on from exercism/javascript-test-runner#1042 (comment). 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 explain 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 the third of three draft PRs, stacked on #106. Merge #105 and #106 first.
What changed
The
tstychecommand took about 3 seconds for lasagna's type tests. The type check inbin/compile.cjstakes about 1.5 seconds, so adding the type tests made the time spent on types about three times longer. I profiled the command, and three things made it slow:vm.compileFunction.tsconfig.jsonexcludes__typetests__, so the service first loads the project fortsconfig.json, finds that the test file isn't in it, and then builds a second, default project for the test file. That second project loads TypeScript's full ESNext library and all 13@typespackages innode_modules. Together the two projects read 333 files.The compile cache doesn't help here. With a cache built for tstyche's copy of TypeScript, the command still took 3.1s.
Now
bin/compile.cjsruns the type tests itself, straight after the type check, in the same process:run.shlooks for__typetests__/*.tst.tsbefore the build step, and setsTYPE_TESTS=trueforbin/compile.cjsif it finds any.TYPE_TESTSis set,bin/compile.cjsloads TypeScript through tstyche'sStoreService. The type check and the type tests then both use tstyche's copy.bin/type-tests.cjsbuilds one more program, with the test files added. Its compiler host hands back the files already parsed and bound by the type check, so only the test files are parsed again.bin/type-tests.cjsgives tstyche a small project service that answers from that program. The small service has only the four methods that tstyche calls. If a later tstyche calls a method missing from it,bin/compile.cjswill crash with aTypeError(for example "closeClientFile is not a function"), andresults.jsonwill hold that stack trace. yarn.lock pins tstyche at 2.1.1, and the three tstyche fixtures intest/types.test.mjswould then fail in CI on the PR that upgrades it.bin/type-tests.cjsuses tstyche's own code, through its exports, for everything else:ConfigServicereads the options and anytstyche.config.json,SelectServicefinds the test files, andTSTycheruns them with--failFast.TSTychewrites its output totstyche.stdout.txtandtstyche.stderr.txtas before, andrun.shreads those files in the same way.The type tests now add about 0.3s to the type check. Exercises without type tests take the same path as before, with
require('typescript')from the compile cache.Smaller changes:
bin/compile.cjsused to let tsc exit as soon as it had reported the diagnostics. It now records the exit code, runs the type tests, writes the JavaScript and then exits with the same code.bin/warm-up.shnow runs the warm-up exercise a second time without its type test, which puts the normal TypeScript module in the cache..dockerignoreletsbin/type-tests.cjsinto the image.Why the type tests and runtime tests run in sequence
I tried running the
tstychecommand at the same time asbin/compile.cjs. On a 2 vCPU machine (one physical core), both together took 4.7s, and one after the other took 4.6s, because both use the CPU the whole time and so only take turns. With this PR the type tests take about 0.3s andnode --testabout 0.4s, so running those two in parallel would save at most a few tenths of a second. I run them one after the other.What students will see
All 135 solutions I checked give byte-identical
results.jsonfiles before and after this change. They were the track's example solutions, the runner's edge cases and a set of lasagna variants: runtime and type tests passing, a failing runtime test, a failing type test, type tests only (passing and failing), a syntax error in the type test file, a missing export, and a tsc error.The type tests now use the same compiler options as the type check, including its
libandtypessettings. Before, tstyche used its own defaults, because the test files fell outsidetsconfig.json. The exercises list__typetests__/*.tst.tsin their owntsconfig.json, so students runningyarn test:typeslocally already get these options. A type test would only behave differently if it relied on ESNext library types or on the looser defaults (for example, acatchvariable typedanyinstead ofunknown).The JavaScript runner
Each JavaScript speed-up has a TypeScript counterpart in this stack, or doesn't apply:
--detectOpenHandles--forceExit--test-force-exit. #105 still runs Jest without--forceExit.node --test, native ES modules and the new test finder (now including exercism/javascript-test-runner#1046)#105 and this PR have no JavaScript counterpart, because the JavaScript runner has no type check and no type tests.
This has been tested in production, and has reduced the median run of an exercise with type tests from 5.2s to 2.4s.
🤖 Generated with Claude Code