Skip to content

perf: ask the TypeScript process for less per build, and bound every batched request - #1752

Merged
johnnyreilly merged 8 commits into
nextfrom
ccr-4cddec7b-7yznjj
Nov 30, 2026
Merged

johnnyreilly merged 8 commits into
nextfrom
ccr-4cddec7b-7yznjj

Conversation

@johnnyreilly

@johnnyreilly johnnyreilly commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Part 1 of 4 from a review of src/ for duplication and performance. #1753, #1754 and #1755 are stacked on this one.

Three changes to what ts-loader asks of the TypeScript process when type checking. transpileOnly builds are not affected.

What changes

Project files are told apart from library files by their metadata. getProjectFiles asked for the source file of every file in the program, default-lib and node_modules files included, and each answer carries that file's syntax tree. It now asks for getSourceFileMetadata, in batched requests. On this repo's own src project (332 files in the program, 9 of them its own) that step went from about 230 ms to about 8 ms.

A compiled file's imports are resolved in the request that compiles it. They took one more request per file. resolveImports is now a request that runs beside the diagnostics and emit, through the API's all.

Every batched request has a bounded size. api.batch takes its requests as arguments, and Node.js 22 fails somewhere between 125,000 and 130,000 of them. The two batches that resolve the imports of the files no loader call compiled had no bound, so a project with that many imports failed with Maximum call stack size exceeded when all of them were resolved at once. They now go through batchInChunks, as one flat list of imports, 1,000 to a message.

Measurements

From the benchmark workflow on this PR: the 300-file fixture, type checking, this branch against next. Each cell is three runs; the third is after the review changes in 3b71cbb.

Ubuntu macOS Windows
Cold build -16%, -20%, -15% -15%, -1%, -16% -20%, -19%, -18%
Cold build, all orphan files -16%, -17%, -16% -15%, -12%, -11% -18%, -17%, -17%
Cold build, declaration on -15%, -18%, -15% -11%, -8%, -14% -16%, -14%, -17%
Rebuild after the hub file changes -4%, -6%, -3% -4%, -3%, -2% -9%, -7%, -8%
Rebuild after a leaf file changes 0%, -1%, 0% 0%, -1%, -4% -6%, +12%, +1%

Two readings stand apart, both on macOS: the second run's cold build, and a +23% on the leaf-file rebuild with declaration on in the third run (not in the table; it was -1% and -10% in the first two, and +1% and 0% on the other platforms in the third). No row reached the benchmark's own threshold for flagging a difference, which is twice the per-sample spread, and the transpileOnly rows stay within the noise.

On the machine this was written on, which is slower than the CI runners, nine cold builds of the 300-file fixture on each branch, alternated, did not overlap: every build on this branch was faster than every build on next (medians 695 ms and 964 ms). A 1,500-file cold build took 15% less time there.

Something to know

A package named by the compiler option must now export all from <compiler>/sync, as TypeScript 7.1 does. One that doesn't gets an error that says so.

Tests

  • New comparison test manyImports: 600 generated files that webpack doesn't bundle, with 288,000 imports between them, over twice what Node.js 22 can pass as arguments. It fails on next with Maximum call stack size exceeded and passes here. The files are generated by the test's webpack.config.js, as they would be 5 MB to commit, and are git-ignored for when the test is built in place.
  • Building that project sends 292 batched messages to the TypeScript process, the largest carrying 1,200 requests.
  • The comparison test guide now says how a test can generate its files, and to stage a new test before running it.
  • Comparison tests (87 suites with the new one) and execution tests (25 suites) pass locally on Linux with webpack 5.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

… batched request

getProjectFiles asked for the source file of every file in the program,
default-lib and node_modules files included, to find out which of them are
the project's own. Each of those requests sends the file's syntax tree. It
now asks for the files' metadata, in batches.

The two batches that resolve imports took one argument per file, and one
per import of every file, with no upper bound. Node.js can't pass much
over 100,000 arguments, which a large project's imports exceed when every
file's imports are resolved again (after a full rescan, or when a file is
created). Every batched request now goes through batchInChunks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5
The imports of each compiled file were resolved in two requests of their
own, after the one for its diagnostics and output. They are now one more
part of that request: resolveImports is a request that asks for the file's
syntax tree and then for what each of its imports resolves to, and the API
runs it beside the others.

The end-of-build recheck resolves the imports of the files no loader call
compiled through the same request, one per file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5
The manyImports comparison test type checks 420 files that webpack doesn't
bundle, with 142,800 imports between them. Before the batches were bounded
it failed with "Maximum call stack size exceeded".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5
@johnnyreilly
johnnyreilly changed the base branch from main to next November 29, 2026 21:09
manyImports is the first test to do so. Also says to stage a new test
before running it: the test script's clean step deletes untracked files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Benchmark (Ubuntu)

Scenario transpileOnly PR branch median (ms) base branch median (ms) Δ vs base branch
Cold build false 417.5 499.0 -16.3%
Incremental rebuild (leaf touch) false 31.8 31.8 +0.2%
Incremental rebuild (hub touch) false 143.0 151.1 -5.3%
Cold build true 260.9 265.6 -1.8%
Incremental rebuild (leaf touch) true 21.2 20.9 +1.5%
Incremental rebuild (hub touch) true 21.4 21.4 +0.1%
Cold build (all orphan files) false 451.0 528.2 -14.6%
Incremental rebuild (hub touch, all orphan files) false 161.3 167.3 -3.6%
Cold build (declaration) false 453.0 531.0 -14.7%
Incremental rebuild (leaf touch, declaration) false 46.8 46.8 -0.1%

PR branch = /home/runner/work/ts-loader/ts-loader, base branch = /home/runner/work/ts-loader/ts-loader-main. 2 warmup + 10 measured iterations per scenario, median reported. Report-only - no threshold fails this check.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Benchmark (macOS)

Scenario transpileOnly PR branch median (ms) base branch median (ms) Δ vs base branch
Cold build false 578.7 642.0 -9.9%
Incremental rebuild (leaf touch) false 50.1 51.0 -1.9%
Incremental rebuild (hub touch) false 119.2 129.4 -7.9%
Cold build true 210.4 219.7 -4.2%
Incremental rebuild (leaf touch) true 52.3 51.8 +1.0%
Incremental rebuild (hub touch) true 52.6 51.3 +2.4%
Cold build (all orphan files) false 552.5 606.6 -8.9%
Incremental rebuild (hub touch, all orphan files) false 245.5 262.3 -6.4%
Cold build (declaration) false 639.2 692.2 -7.7%
Incremental rebuild (leaf touch, declaration) false 122.0 113.4 +7.5%

PR branch = /Users/runner/work/ts-loader/ts-loader, base branch = /Users/runner/work/ts-loader/ts-loader-main. 2 warmup + 10 measured iterations per scenario, median reported. Report-only - no threshold fails this check.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Benchmark (Windows)

Scenario transpileOnly PR branch median (ms) base branch median (ms) Δ vs base branch
Cold build false 737.8 924.7 -20.2%
Incremental rebuild (leaf touch) false 51.2 53.9 -4.9%
Incremental rebuild (hub touch) false 246.7 263.9 -6.5%
Cold build true 431.9 438.6 -1.5%
Incremental rebuild (leaf touch) true 35.3 33.9 +4.2%
Incremental rebuild (hub touch) true 33.0 33.1 -0.2%
Cold build (all orphan files) false 860.6 1034.1 -16.8%
Incremental rebuild (hub touch, all orphan files) false 310.6 334.3 -7.1%
Cold build (declaration) false 902.5 1092.3 -17.4%
Incremental rebuild (leaf touch, declaration) false 360.6 367.2 -1.8%

PR branch = C:\source\ts-loader, base branch = C:\source\ts-loader-main. 2 warmup + 10 measured iterations per scenario, median reported. Report-only - no threshold fails this check.

The entry quoted timings from the machine the change was written on, which
gains more from it than the CI runners do. On Ubuntu, macOS and Windows
the benchmark workflow measured a 300-file cold build at 15 to 20% less
time, and a rebuild after the hub file changes at 4 to 9% less.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

@johnnyreilly johnnyreilly left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No bugs found that this PR introduces. The inline comments are small points about wording and the new test. All 45 checks pass on 79a4a9f.

Checked locally on Linux with Node.js 22 and TypeScript 7.1.0-beta:

  • manyImports passes on this branch and fails on next with Maximum call stack size exceeded, as described.
  • The basic comparison test sends 84 messages to the TypeScript process on this branch, against 270 on next.

Generated by Claude Code

Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
Comment thread src/typeScriptApi.ts Resolved
Comment thread src/typeScriptApi.ts Resolved
Comment thread src/typeScriptApi.ts Resolved
From the review of #1752:

- batchInChunks bounded how many files' imports went in a batch, and each
  file's request fanned out into one per import, so the 142,800 imports of
  the manyImports test still went in one message. The imports of many
  files are now resolved as one flat list, 1,000 to a message.
  resolveImports stays for the one file being compiled, and says that it
  takes that file's imports as arguments.
- The end-of-build recheck's diagnostics and the declaration emit are
  stored a chunk at a time again, as on next. Storing them once every
  chunk had returned dropped the ones already received if the process died
  part-way.
- manyImports generates 288,000 imports, over twice what Node.js 22 can
  pass as arguments; 142,800 was 10 to 14% over.
- Changelog: a compiled file's imports took one more request, not two (the
  first of the two old batches found the file's syntax tree cached, and
  sent nothing); and the cold build figure is "up to about 20%", as one of
  two macOS runs showed no gain.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5
Building the test in place, as the comparison test guide suggests, writes
them beside its webpack.config.js, where they showed up as 600 untracked
files. From the review of #1752.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5
@johnnyreilly
johnnyreilly merged commit 468655c into next Nov 30, 2026
45 checks passed
@johnnyreilly
johnnyreilly deleted the ccr-4cddec7b-7yznjj branch November 30, 2026 06:45
johnnyreilly added a commit that referenced this pull request Nov 30, 2026
* perf: classify a program's files from their metadata, and bound every batched request

getProjectFiles asked for the source file of every file in the program,
default-lib and node_modules files included, to find out which of them are
the project's own. Each of those requests sends the file's syntax tree. It
now asks for the files' metadata, in batches.

The two batches that resolve imports took one argument per file, and one
per import of every file, with no upper bound. Node.js can't pass much
over 100,000 arguments, which a large project's imports exceed when every
file's imports are resolved again (after a full rescan, or when a file is
created). Every batched request now goes through batchInChunks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* perf: resolve a compiled file's imports in the request that compiles it

The imports of each compiled file were resolved in two requests of their
own, after the one for its diagnostics and output. They are now one more
part of that request: resolveImports is a request that asks for the file's
syntax tree and then for what each of its imports resolves to, and the API
runs it beside the others.

The end-of-build recheck resolves the imports of the files no loader call
compiled through the same request, one per file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* test: a project with more imports than Node.js can pass as arguments

The manyImports comparison test type checks 420 files that webpack doesn't
bundle, with 142,800 imports between them. Before the batches were bounded
it failed with "Maximum call stack size exceeded".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* refactor: remove dead code

No change in behaviour.

- registerTypeScriptDependencies checked transpileOnly, but is only
  called once getTypeScriptEmit has returned for transpileOnly.
- replaceTypeScriptApi filtered the orphan roots for ones that are gone,
  which forgetMissingFileLayers has just dropped.
- TSFile.fileName was written and never read.
- The instance cache had a stand-in key for a loader context with no
  compiler. getTypeScriptInstance taps that compiler's hooks, so there
  always is one; it now reads it once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* docs: changelog for #1752

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* docs: how a comparison test can generate its files

manyImports is the first test to do so. Also says to stage a new test
before running it: the test script's clean step deletes untracked files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* docs: quote the benchmark workflow's numbers in the changelog

The entry quoted timings from the machine the change was written on, which
gains more from it than the CI runners do. On Ubuntu, macOS and Windows
the benchmark workflow measured a 300-file cold build at 15 to 20% less
time, and a rebuild after the hub file changes at 4 to 9% less.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* fix: bound the imports in a batch, not the files; address review

From the review of #1752:

- batchInChunks bounded how many files' imports went in a batch, and each
  file's request fanned out into one per import, so the 142,800 imports of
  the manyImports test still went in one message. The imports of many
  files are now resolved as one flat list, 1,000 to a message.
  resolveImports stays for the one file being compiled, and says that it
  takes that file's imports as arguments.
- The end-of-build recheck's diagnostics and the declaration emit are
  stored a chunk at a time again, as on next. Storing them once every
  chunk had returned dropped the ones already received if the process died
  part-way.
- manyImports generates 288,000 imports, over twice what Node.js 22 can
  pass as arguments; 142,800 was 10 to 14% over.
- Changelog: a compiled file's imports took one more request, not two (the
  first of the two old batches found the file's syntax tree cached, and
  sent nothing); and the cold build figure is "up to about 20%", as one of
  two macOS runs showed no gain.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

---------

Co-authored-by: Claude <noreply@anthropic.com>
johnnyreilly added a commit that referenced this pull request Nov 30, 2026
…ck into steps (#1754)

* perf: classify a program's files from their metadata, and bound every batched request

getProjectFiles asked for the source file of every file in the program,
default-lib and node_modules files included, to find out which of them are
the project's own. Each of those requests sends the file's syntax tree. It
now asks for the files' metadata, in batches.

The two batches that resolve imports took one argument per file, and one
per import of every file, with no upper bound. Node.js can't pass much
over 100,000 arguments, which a large project's imports exceed when every
file's imports are resolved again (after a full rescan, or when a file is
created). Every batched request now goes through batchInChunks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* perf: resolve a compiled file's imports in the request that compiles it

The imports of each compiled file were resolved in two requests of their
own, after the one for its diagnostics and output. They are now one more
part of that request: resolveImports is a request that asks for the file's
syntax tree and then for what each of its imports resolves to, and the API
runs it beside the others.

The end-of-build recheck resolves the imports of the files no loader call
compiled through the same request, one per file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* refactor: name what was spelled out in several places

No change in behaviour is intended.

- getPrimaryProgram and getOrphanProgram look a snapshot's programs up.
- parseProjectConfig is the project's config with the loader options'
  overrides, if any. transpileOnly now takes the overridden config from
  the same per-build cache as type checking does.
- buildLoaderErrors builds a compiled file's errors for its module.
- addConfigDependency, toAssetPath and closeTypeScriptApi each replace a
  pair of copies; getOrCreate replaces five get-then-set blocks.
- The two path cache functions differed in one expression, and are one.
- The modules of a build are indexed by file once, not once for the
  recheck and again for reporting.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* test: a project with more imports than Node.js can pass as arguments

The manyImports comparison test type checks 420 files that webpack doesn't
bundle, with 142,800 imports between them. Before the batches were bounded
it failed with "Maximum call stack size exceeded".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* refactor: remove dead code

No change in behaviour.

- registerTypeScriptDependencies checked transpileOnly, but is only
  called once getTypeScriptEmit has returned for transpileOnly.
- replaceTypeScriptApi filtered the orphan roots for ones that are gone,
  which forgetMissingFileLayers has just dropped.
- TSFile.fileName was written and never read.
- The instance cache had a stand-in key for a loader context with no
  compiler. getTypeScriptInstance taps that compiler's hooks, so there
  always is one; it now reads it once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* refactor: split the end-of-build recheck into its steps

recheckAllTransitiveDependants was 290 lines doing six things in a row. It
now reads as those steps: find a file to open the project with, bring the
programs up to date, collect the files to check, check them, emit the
declarations that may have changed, and forget the files that are gone.

The code of each step is as it was. One thing moves: the names of the
layers hidden since the last recheck are now taken once the programs are
up to date, not just before the orphan program is. Nothing between the two
points adds to them, so the files checked are the same; if bringing the
orphan program up to date throws, they are now kept for the next recheck.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* docs: changelog for #1752

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* docs: how a comparison test can generate its files

manyImports is the first test to do so. Also says to stage a new test
before running it: the test script's clean step deletes untracked files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* docs: quote the benchmark workflow's numbers in the changelog

The entry quoted timings from the machine the change was written on, which
gains more from it than the CI runners do. On Ubuntu, macOS and Windows
the benchmark workflow measured a 300-file cold build at 15 to 20% less
time, and a rebuild after the hub file changes at 4 to 9% less.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* fix: bound the imports in a batch, not the files; address review

From the review of #1752:

- batchInChunks bounded how many files' imports went in a batch, and each
  file's request fanned out into one per import, so the 142,800 imports of
  the manyImports test still went in one message. The imports of many
  files are now resolved as one flat list, 1,000 to a message.
  resolveImports stays for the one file being compiled, and says that it
  takes that file's imports as arguments.
- The end-of-build recheck's diagnostics and the declaration emit are
  stored a chunk at a time again, as on next. Storing them once every
  chunk had returned dropped the ones already received if the process died
  part-way.
- manyImports generates 288,000 imports, over twice what Node.js 22 can
  pass as arguments; 142,800 was 10 to 14% over.
- Changelog: a compiled file's imports took one more request, not two (the
  first of the two old batches found the file's syntax tree cached, and
  sent nothing); and the cold build figure is "up to about 20%", as one of
  two macOS runs showed no gain.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

---------

Co-authored-by: Claude <noreply@anthropic.com>
johnnyreilly added a commit that referenced this pull request Nov 30, 2026
* perf: classify a program's files from their metadata, and bound every batched request

getProjectFiles asked for the source file of every file in the program,
default-lib and node_modules files included, to find out which of them are
the project's own. Each of those requests sends the file's syntax tree. It
now asks for the files' metadata, in batches.

The two batches that resolve imports took one argument per file, and one
per import of every file, with no upper bound. Node.js can't pass much
over 100,000 arguments, which a large project's imports exceed when every
file's imports are resolved again (after a full rescan, or when a file is
created). Every batched request now goes through batchInChunks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* perf: resolve a compiled file's imports in the request that compiles it

The imports of each compiled file were resolved in two requests of their
own, after the one for its diagnostics and output. They are now one more
part of that request: resolveImports is a request that asks for the file's
syntax tree and then for what each of its imports resolves to, and the API
runs it beside the others.

The end-of-build recheck resolves the imports of the files no loader call
compiled through the same request, one per file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* refactor: name what was spelled out in several places

No change in behaviour is intended.

- getPrimaryProgram and getOrphanProgram look a snapshot's programs up.
- parseProjectConfig is the project's config with the loader options'
  overrides, if any. transpileOnly now takes the overridden config from
  the same per-build cache as type checking does.
- buildLoaderErrors builds a compiled file's errors for its module.
- addConfigDependency, toAssetPath and closeTypeScriptApi each replace a
  pair of copies; getOrCreate replaces five get-then-set blocks.
- The two path cache functions differed in one expression, and are one.
- The modules of a build are indexed by file once, not once for the
  recheck and again for reporting.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* test: a project with more imports than Node.js can pass as arguments

The manyImports comparison test type checks 420 files that webpack doesn't
bundle, with 142,800 imports between them. Before the batches were bounded
it failed with "Maximum call stack size exceeded".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* refactor: remove dead code

No change in behaviour.

- registerTypeScriptDependencies checked transpileOnly, but is only
  called once getTypeScriptEmit has returned for transpileOnly.
- replaceTypeScriptApi filtered the orphan roots for ones that are gone,
  which forgetMissingFileLayers has just dropped.
- TSFile.fileName was written and never read.
- The instance cache had a stand-in key for a loader context with no
  compiler. getTypeScriptInstance taps that compiler's hooks, so there
  always is one; it now reads it once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* refactor: split the end-of-build recheck into its steps

recheckAllTransitiveDependants was 290 lines doing six things in a row. It
now reads as those steps: find a file to open the project with, bring the
programs up to date, collect the files to check, check them, emit the
declarations that may have changed, and forget the files that are gone.

The code of each step is as it was. One thing moves: the names of the
layers hidden since the last recheck are now taken once the programs are
up to date, not just before the orphan program is. Nothing between the two
points adds to them, so the files checked are the same; if bringing the
orphan program up to date throws, they are now kept for the next recheck.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* docs: correct and de-duplicate comments in src

Comments only; no code changes.

Corrected:
- The inert loader options are four, not two; the note on them named
  only resolveModuleName and resolveTypeReferenceDirective, and pointed
  at a test that covers one of them.
- The note on why changed directories are listed again sat in the branch
  taken when listing them fails.
- colors.ts said both variants are built up front; one is built on demand.
- The benchmark README named a file and four functions of ts-loader 9.

Said once instead of several times: why API and webpack file names are
compared through toComparablePath, why a node_modules file has to be a
root, the three ways the API is told what changed, and when diagnostics
are reported. Each now points at the place that explains it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* docs: changelog for #1752

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* docs: how a comparison test can generate its files

manyImports is the first test to do so. Also says to stage a new test
before running it: the test script's clean step deletes untracked files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* docs: quote the benchmark workflow's numbers in the changelog

The entry quoted timings from the machine the change was written on, which
gains more from it than the CI runners do. On Ubuntu, macOS and Windows
the benchmark workflow measured a 300-file cold build at 15 to 20% less
time, and a rebuild after the hub file changes at 4 to 9% less.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

* fix: bound the imports in a batch, not the files; address review

From the review of #1752:

- batchInChunks bounded how many files' imports went in a batch, and each
  file's request fanned out into one per import, so the 142,800 imports of
  the manyImports test still went in one message. The imports of many
  files are now resolved as one flat list, 1,000 to a message.
  resolveImports stays for the one file being compiled, and says that it
  takes that file's imports as arguments.
- The end-of-build recheck's diagnostics and the declaration emit are
  stored a chunk at a time again, as on next. Storing them once every
  chunk had returned dropped the ones already received if the process died
  part-way.
- manyImports generates 288,000 imports, over twice what Node.js 22 can
  pass as arguments; 142,800 was 10 to 14% over.
- Changelog: a compiled file's imports took one more request, not two (the
  first of the two old batches found the file's syntax tree cached, and
  sent nothing); and the cold build figure is "up to about 20%", as one of
  two macOS runs showed no gain.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2Jv7JZWr3VUxCkXiKB5e5

---------

Co-authored-by: Claude <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.

2 participants