Mike Sherov
Core UX Team @ Skillshare
I am performance, and so can you!
We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%
Given n inputs, and some small constant m:
Why do we see a lot of n^2 in JS?
var obj1 = {a: 1}
var obj2 = {b: 2}
console.log('es5 - broken, but O(1)');
function SetAddBroken(obj, set) {
set[obj] = true;
}
function SetHasBroken(obj, set) {
return !!set[obj];
}
var fakeSet = {};
SetAddBroken(obj1, fakeSet);
console.log(SetHasBroken(obj1, fakeSet));
console.log(SetHasBroken(obj2, fakeSet));
console.log(fakeSet)
console.log('es5 - works, but O(n)');
function SetAddWorks(obj, set) {
if (!set.includes(obj)) { set.push(obj); }
}
function SetHasWorks(obj, set) {
return set.includes(obj);
}
var fakeSet2 = [];
SetAddWorks(obj1, fakeSet2);
console.log(SetHasWorks(obj1, fakeSet2));
console.log(SetHasWorks(obj2, fakeSet2));
console.log('es6 - works, and O(1)');
var set = new Set();
set.add(obj1);
console.log(set.has(obj1));
console.log(set.has(obj2));
Plug in your power cord
`docker-machine down`
`sudo mdutil -a -i off`
Use `nvm` to manage runtimes
Test in the most common envs for your users