Improve webpack performance (~ 80ms -> 15ms)
This commit is contained in:
parent
0677df7818
commit
86c4bb7f8c
2 changed files with 29 additions and 4 deletions
|
@ -53,6 +53,18 @@ function patchPush() {
|
||||||
return originalMod(module, exports, require);
|
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) {
|
for (const callback of listeners) {
|
||||||
try {
|
try {
|
||||||
callback(exports);
|
callback(exports);
|
||||||
|
@ -65,12 +77,19 @@ function patchPush() {
|
||||||
if (filter(exports)) {
|
if (filter(exports)) {
|
||||||
subscriptions.delete(filter);
|
subscriptions.delete(filter);
|
||||||
callback(exports);
|
callback(exports);
|
||||||
} else for (const nested in exports) {
|
} else if (typeof exports === "object") {
|
||||||
|
if (exports.default && filter(exports.default)) {
|
||||||
|
subscriptions.delete(filter);
|
||||||
|
callback(exports.default);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const nested in exports) if (nested.length < 3) {
|
||||||
if (exports[nested] && filter(exports[nested])) {
|
if (exports[nested] && filter(exports[nested])) {
|
||||||
subscriptions.delete(filter);
|
subscriptions.delete(filter);
|
||||||
callback(exports[nested]);
|
callback(exports[nested]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("Error while firing callback for webpack chunk", err);
|
logger.error("Error while firing callback for webpack chunk", err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,15 @@ export function find(filter: FilterFn, getDefault = true) {
|
||||||
|
|
||||||
if (filter(mod.exports))
|
if (filter(mod.exports))
|
||||||
return mod.exports;
|
return mod.exports;
|
||||||
|
|
||||||
|
if (typeof mod.exports !== "object") continue;
|
||||||
|
|
||||||
if (mod.exports.default && filter(mod.exports.default))
|
if (mod.exports.default && filter(mod.exports.default))
|
||||||
return getDefault ? mod.exports.default : mod.exports;
|
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];
|
const nested = mod.exports[nestedMod];
|
||||||
if (nested && filter(nested)) return nested;
|
if (nested && filter(nested)) return nested;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue