diff options
author | Vendicated <vendicated@riseup.net> | 2022-09-28 22:49:46 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-09-28 22:49:46 +0200 |
commit | 86c4bb7f8c34003168ac5380a01401fcbeac4013 (patch) | |
tree | a8c47a9004bd92261e81ed046d31137d99afaca7 | |
parent | 0677df781840461f9a0b11ed08a2c9f72a521c84 (diff) | |
download | Vencord-86c4bb7f8c34003168ac5380a01401fcbeac4013.tar.gz Vencord-86c4bb7f8c34003168ac5380a01401fcbeac4013.tar.bz2 Vencord-86c4bb7f8c34003168ac5380a01401fcbeac4013.zip |
Improve webpack performance (~ 80ms -> 15ms)
-rw-r--r-- | src/utils/patchWebpack.ts | 25 | ||||
-rw-r--r-- | src/webpack/webpack.ts | 8 |
2 files changed, 29 insertions, 4 deletions
diff --git a/src/utils/patchWebpack.ts b/src/utils/patchWebpack.ts index ce29c82..0508968 100644 --- a/src/utils/patchWebpack.ts +++ b/src/utils/patchWebpack.ts @@ -53,6 +53,18 @@ function patchPush() { return originalMod(module, exports, require); } + // There are (at the time of writing) 11 modules exporting the window + // Make these non enumerable to improve webpack search performance + if (module.exports === window) { + Object.defineProperty(require.c, id, { + value: require.c[id], + enumerable: false, + configurable: true, + writable: true + }); + return; + } + for (const callback of listeners) { try { callback(exports); @@ -65,10 +77,17 @@ function patchPush() { if (filter(exports)) { subscriptions.delete(filter); callback(exports); - } else for (const nested in exports) { - if (exports[nested] && filter(exports[nested])) { + } else if (typeof exports === "object") { + if (exports.default && filter(exports.default)) { subscriptions.delete(filter); - callback(exports[nested]); + callback(exports.default); + } + + for (const nested in exports) if (nested.length < 3) { + if (exports[nested] && filter(exports[nested])) { + subscriptions.delete(filter); + callback(exports[nested]); + } } } } catch (err) { 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; } |