From 86c4bb7f8c34003168ac5380a01401fcbeac4013 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 28 Sep 2022 22:49:46 +0200 Subject: Improve webpack performance (~ 80ms -> 15ms) --- src/webpack/webpack.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/webpack/webpack.ts') diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index 64e2310..9e550a4 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -44,9 +44,15 @@ export function find(filter: FilterFn, getDefault = true) { if (filter(mod.exports)) return mod.exports; + + if (typeof mod.exports !== "object") continue; + if (mod.exports.default && filter(mod.exports.default)) return getDefault ? mod.exports.default : mod.exports; - for (const nestedMod in mod.exports) { + + // is 3 is the longest obfuscated export? + // the length check makes search about 20% faster + for (const nestedMod in mod.exports) if (nestedMod.length < 3) { const nested = mod.exports[nestedMod]; if (nested && filter(nested)) return nested; } -- cgit