You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
v10: in watch mode every recompiled file is read from disk a second time #1744
Follow-up from the review of #1741 (the comment on layerFileContents, raised at 89b1b78 and still present at 5d4f461). Found by reading the code; the cost has not been measured on its own.
What happens
layerFileContents in src/typeScriptApi.ts decides whether a compiled file's text differs from what the TypeScript process reads from disk. Since #1741 it compares with the real disk (readDiskFile, a synchronous fs.readFileSync), because webpack's input file system can hold virtual modules the TypeScript process can't see. On next it read through webpack's cached input file system, which had just read the same file.
Every compiled file is added to everLayeredFiles, so the shortcut only applies the first time a file is compiled. From the second compile on, each recompiled file costs one uncached whole-file read on the loader thread.
Scenario
A branch switch in watch mode rebuilds 2,000 TypeScript files: 2,000 extra fs.readFileSync calls, which the comment above the code says it means to avoid ("reading every compiled file again here would only repeat that").
#1741's benchmark at 1,200 files shows +4.5% on "Incremental rebuild (hub touch)" against next, and its description flags that as the number to look at again. This read may be the cause; that has not been confirmed.
Possible fixes
Only add a file to everLayeredFiles when its layer actually differs from disk, so a file that always matches the disk keeps the shortcut.
Cache the disk text by mtime and size.
Read the disk only when webpack's input file system is not the real one, or the file is not a real file there.
Any of these needs to keep #1736's behaviour: a virtual module, or a file another loader transformed, must still be sent again to a restarted TypeScript process.
Done when
A rebuild that recompiles N unchanged-on-disk files does not do N extra synchronous disk reads.
virtualModuleWatch and the compilerProcessRestart* comparison tests still pass.
The hub-touch rebuild benchmark is re-run against next and the result recorded.
Fixed on next by #1756 (6e7734f), listed under 10.0.0-beta.2 in the changelog.
#1756 records which files were on disk, under the name webpack watches them by, when they were last compiled (filesSeenOnDisk). A file is looked at on disk when it is first compiled, when the text handed to the loader has changed, or when webpack's watcher has reported it; otherwise ts-loader keeps what it found the last time.
Against "done when":
A rebuild that recompiles N unchanged-on-disk files no longer does N extra reads. perf: stop reading every recompiled file from disk on a rebuild #1756 counted, on the 300-file benchmark project where 157 files import the changed one: 158 such reads per rebuild before, 1 after.
virtualModuleWatch and the compilerProcessRestart* comparison tests pass on next.
Activity
johnnyreilly commentedon Dec 1, 2026
Fixed on
nextby #1756 (6e7734f), listed under 10.0.0-beta.2 in the changelog.#1756 records which files were on disk, under the name webpack watches them by, when they were last compiled (
filesSeenOnDisk). A file is looked at on disk when it is first compiled, when the text handed to the loader has changed, or when webpack's watcher has reported it; otherwise ts-loader keeps what it found the last time.Against "done when":
virtualModuleWatchand thecompilerProcessRestart*comparison tests pass onnext.nextand recorded in perf: stop reading every recompiled file from disk on a rebuild #1756: roughly 5% to 18% less time per rebuild on macOS and Windows, and 1% to 3% less on Linux.Generated by Claude Code