Skip to content

Commit

Permalink
Optimize fileExists callback path (#1266)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
berickson1 authored Mar 11, 2021
1 parent 953358e commit c2c1aef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v8.0.18
* [Perf: Optimize fileExists callback path](https://github.com/TypeStrong/ts-loader/issues/1266) - thanks @berickson1

## v8.0.17
* [Included correct webpack source location in emitted errors](https://github.com/TypeStrong/ts-loader/issues/1199) - thanks @lorenzodallavecchia

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "8.0.17",
"version": "8.0.18",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist",
Expand Down
12 changes: 8 additions & 4 deletions src/servicesHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,14 @@ export function makeSolutionBuilderHost(
scriptRegex,
loader,
instance,
fileName =>
!!instance.files.has(filePathKeyMapper(fileName)) ||
!!instance.otherFiles.get(filePathKeyMapper(fileName)) ||
compiler.sys.fileExists(fileName),
fileName => {
const filePathKey = filePathKeyMapper(fileName);
return (
instance.files.has(filePathKey) ||
instance.otherFiles.has(filePathKey) ||
compiler.sys.fileExists(fileName)
);
},
/*enableFileCaching*/ true
);

Expand Down

0 comments on commit c2c1aef

Please sign in to comment.