From b6029eb6271e325045aab627f133095151d78016 Mon Sep 17 00:00:00 2001 From: Brent Erickson Date: Wed, 10 Mar 2021 13:33:00 -0800 Subject: [PATCH 1/2] 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 --- src/servicesHost.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/servicesHost.ts b/src/servicesHost.ts index 170d03918..2447ba419 100644 --- a/src/servicesHost.ts +++ b/src/servicesHost.ts @@ -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 ); From 2b8fc3c7a958867dcef720f0cc30b3e270ff727a Mon Sep 17 00:00:00 2001 From: Brent Erickson Date: Wed, 10 Mar 2021 22:45:45 -0800 Subject: [PATCH 2/2] Update Changelog & package.json --- CHANGELOG.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96b67abfa..96a3e42a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index c13d40f41..b9760fb33 100644 --- a/package.json +++ b/package.json @@ -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",