From a crazy long investigation in Marak/colors.js#151
In parse/index.js:
function addParent(obj, parent) {
var isNode = obj && typeof obj.type === 'string';
var childParent = isNode ? obj : parent;
for (var k in obj) {
var value = obj[k];
if (Array.isArray(value)) {
value.forEach(function(v) { addParent(v, childParent); });
} else if (value && typeof value === 'object') {
addParent(value, childParent);
}
}
if (isNode) {
Object.defineProperty(obj, 'parent', {
configurable: true,
writable: true,
enumerable: false,
value: parent || null
});
}
return obj;
}
Look at var value = obj[k];...
If obj is a String (such as a selector), its keys will be iterated over unnecessarily. If require('colors') is being used in the codebase, the keys will also include all colors getter methods such as bold, yellow, and most dangerously, the terrifying zalgo. All these getters are being invoked for every string. zalgo uses Math.random() which causes a huge slow down.
This showed up in a CPU profile I was running to debug my slow webpack compile, while using bootstra-loader, and resolve-url-loader which depends on rework.
Removing zalgo sped up my compile from 14s to 7s.
Fix should be simple. Check if its a String and skip it in the for loop.
This should give an instant huge speed up to any webpack and bootstrap-loader users. Dependants are all using semver properly.
From a crazy long investigation in Marak/colors.js#151
In
parse/index.js:Look at
var value = obj[k];...If
objis aString(such as a selector), its keys will be iterated over unnecessarily. Ifrequire('colors')is being used in the codebase, the keys will also include allcolorsgetter methods such asbold,yellow, and most dangerously, the terrifyingzalgo. All these getters are being invoked for every string.zalgousesMath.random()which causes a huge slow down.This showed up in a CPU profile I was running to debug my slow webpack compile, while using
bootstra-loader, andresolve-url-loaderwhich depends onrework.Removing
zalgosped up my compile from 14s to 7s.Fix should be simple. Check if its a
Stringand skip it in the for loop.This should give an instant huge speed up to any
webpackandbootstrap-loaderusers. Dependants are all using semver properly.