Skip to content

Commit c2c1aef

Browse files
authored
Optimize fileExists callback path (#1266)
* Optimize fileExists callback path Instead of looking up filePathKey twice, cache in in the local scope. This isn't a hugely expensive lookup path, but is a hot path on large project recompiles (especially after caches are blown away). Profiling shows that even the Map lookup shows non-trivial cache lookup aggregate time * Update Changelog & package.json
1 parent 953358e commit c2c1aef

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v8.0.18
4+
* [Perf: Optimize fileExists callback path](https://github.com/TypeStrong/ts-loader/issues/1266) - thanks @berickson1
5+
36
## v8.0.17
47
* [Included correct webpack source location in emitted errors](https://github.com/TypeStrong/ts-loader/issues/1199) - thanks @lorenzodallavecchia
58

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "8.0.17",
3+
"version": "8.0.18",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist",

src/servicesHost.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,14 @@ export function makeSolutionBuilderHost(
683683
scriptRegex,
684684
loader,
685685
instance,
686-
fileName =>
687-
!!instance.files.has(filePathKeyMapper(fileName)) ||
688-
!!instance.otherFiles.get(filePathKeyMapper(fileName)) ||
689-
compiler.sys.fileExists(fileName),
686+
fileName => {
687+
const filePathKey = filePathKeyMapper(fileName);
688+
return (
689+
instance.files.has(filePathKey) ||
690+
instance.otherFiles.has(filePathKey) ||
691+
compiler.sys.fileExists(fileName)
692+
);
693+
},
690694
/*enableFileCaching*/ true
691695
);
692696

0 commit comments

Comments
 (0)