perf: build a solution on the programs of the build before it - #342
Merged
Merged
Conversation
A rebuild in `build` mode made every project's program from nothing: `tsc -b` reads what it can back from `.tsbuildinfo`, but the sources are parsed and the project checked over again. The builder is handed a `createProgram` of ours now, which keeps the parsed files and hands each project the program the last build left it. Over a two-project, 302-file solution, a rebuild after one edit falls from 468 ms to 149 ms (medians of 10, three runs) and holds 267 MB rather than 412 MB; a first build is unchanged at ~1240 ms.
alexander-akait
force-pushed
the
perf/reuse-the-built-solution
branch
from
September 14, 2026 04:51
8867de9 to
86e0f2c
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.
Summary
A rebuild in
buildmode made every project's program from nothing.tsc -breads what it can back from.tsbuildinfo, but the sources are parsed and the project checked over again — so the one thing the non-buildpath already does, keeping its program between rebuilds (#331), the solution path did not.The solution builder's host takes a
createProgramof its own, which is the only hook it exposes. Ours keeps the parsed source files and hands each project the program the last build left it.Measured, and the alternative was measured too. Over a generated two-project, 302-file solution, one file edited between passes, medians of 10 rebuilds over three interleaved runs:
createSolutionBuilderWithWatch— the obvious candidate, and whatfork-ts-checker-webpack-pluginuses — was tried first and rejected on the numbers: with its watchers replaced by ours (webpack owns the watching here, per #334) its rebuilds were no faster than today's ~500 ms, it held 503 MB, and after the second passinvalidateProjectstopped rebuilding at all, so it answered from stale programs. It only works with TypeScript's own file watchers, which would duplicate webpack's.One thing measuring turned up that this PR does not fix.
buildmode inheritstsc -b's timestamp up-to-date check, so an edit whose mtime does not exceed the previous build's outputs — an edit made while a build is running — is silently skipped and reported as clean until something else changes. It reproduces onmain(status=UpToDate, input mtime equal to.tsbuildinfo's) and is unrelated to this change; worth its own issue.What kind of change does this PR introduce?
perf
Did you add tests for your changes?
Yes —
test/typescript/references.test.jswatches a solution over an edit and asserts each project of the second build is handed the very same program object the first returned.tsc -breads an old program back from.tsbuildinfoeither way, so the recorder mock had to record object identity rather than "was there an old program": with that, reverting the change fails the test.Does this PR introduce a breaking change?
No — same diagnostics, same options.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a — no option changed.
Use of AI
Claude Code wrote the benchmark, measured the three candidate designs, wrote the change, the test and this description; I reviewed all of it.
Rebased onto
mainnow that #341 has landed, so this is one commit. #343 sits on top of it.🤖 Generated with Claude Code
https://claude.ai/code/session_01GzZci4NQeiqwdrVfd7dGXy