From 2d08d0c6846a6a5e8d41897e34851c9905fd8264 Mon Sep 17 00:00:00 2001 From: Raymond Cohen Date: Tue, 26 Sep 2023 14:09:17 -0400 Subject: [PATCH] short circuit decodeImplicitModules and decodeVirtualPairComponent with filename includes check --- packages/core/src/virtual-content.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/core/src/virtual-content.ts b/packages/core/src/virtual-content.ts index bd25a2c68..02d428d28 100644 --- a/packages/core/src/virtual-content.ts +++ b/packages/core/src/virtual-content.ts @@ -124,6 +124,10 @@ export function virtualPairComponent(hbsModule: string, jsModule: string | null) function decodeVirtualPairComponent( filename: string ): { relativeHBSModule: string; relativeJSModule: string | null; debugName: string } | null { + // Performance: avoid paying regex exec cost unless needed + if (!filename.includes(pairComponentMarker)) { + return null; + } let match = pairComponentPattern.exec(filename); if (!match) { return null; @@ -186,6 +190,10 @@ const implicitModulesPattern = /(?.*)[\\/]-embroider-implicit-(? export function decodeImplicitModules( filename: string ): { type: 'implicit-modules' | 'implicit-test-modules'; fromFile: string } | undefined { + // Performance: avoid paying regex exec cost unless needed + if (!filename.includes('-embroider-implicit-')) { + return; + } let m = implicitModulesPattern.exec(filename); if (m) { return {