Live data from Hacker News

JS MythBusters – An optimization handbook from a high level point of view

mythbusters.js.org

21–27 of 27 posts

Re: JS MythBusters – An optimization handbook from a high level point of view

#21

I'm not sure how this can be called "mythbusters" when it doesn't provide evidence for how some optimizations are better than others. Seems likely to produce more myths rather than debunk them.

Good point. It's the exact opposite of mythbusting.

Re: JS MythBusters – An optimization handbook from a high level point of view

#22

Some of these performance tips are just not believable without some kind of justification. I'm to believe that garbage collection can't work if you use delete? That seems pretty silly.

This one actually seems fair to me. They're not saying that GC won't kick in on the value the deleted property used to point to, but rather that using `delete` on a property can be more expensive than you need if you're just trying to let the GC know something can be cleaned up. This is because optimized JIT code and caches guard on the structure of objects that pass through them, and changing that structure (eg. deleting a property) will lead to deoptimizations / tossing away some of that code.

On SpiderMonkey, deleting a property that isn't the last one that was defined may incur a "dictionary mode" conversion [0]. This means the information describing each object property, which is usually immutable and shared between similar objects, will be copied one-by-one into a unique chain owned by the particular object instance. This can only happen once per object instance, however, and subsequent usages of `delete` on its properties will be less expensive -- but still more expensive than simply setting property values to `null`. I believe something similar happens with V8's "hidden classes" mechanism.

[0] https://dxr.mozilla.org/mozilla-central/source/js/src/vm/Sha...

Re: JS MythBusters – An optimization handbook from a high level point of view

#24

Some of these performance tips are just not believable without some kind of justification. I'm to believe that garbage collection can't work if you use delete? That seems pretty silly.

This one actually seems fair to me. They're not saying that GC won't kick in on the value the deleted property used to point to, but rather that using `delete` on a property can be more expensive than you need if you're just trying to let the GC know something can be cleaned up. This is because optimized JIT code and caches guard on the structure of objects that pass through them, and changing that structure (eg. del…

I'm not saying it's not true. I don't know enough deep javascript magic to make that claim. It just didn't sound true, given that they've provided no supporting information or even a plausible-sounding explanation of why one way is better than another way.

If the entire site were rewritten using this level of detail plus benchmarks, it would be 10x more useful.

Re: JS MythBusters – An optimization handbook from a high level point of view

#25
post #14

One of the defining thing about MythBusters was that they'd take a myth, build an experiment with at least some notion of control, and then carry it out, so you can actually see the results. Instead this site seems to be "regurgitate myths". e.g. http://mythbusters.js.org/workflow/boolean-conditions.html "Avoid using >= and <= unless necessary. It’s faster to use a simpler comparison." There's a trivial code example,…

I'm extremely skeptical of that claim, too. As far as I can tell SpiderMonkey for example will emit practically exactly the same code for >= and They also recommend using `let` and `const` over `var` for performance reasons in the "Scope" section, but I have to ask whether they benchmarked that at all. Engines may grow to take advantage of these signals over time for further optimization, but at the moment many ES6 f…

[deleted]

Re: JS MythBusters – An optimization handbook from a high level point of view

#26
post #14

One of the defining thing about MythBusters was that they'd take a myth, build an experiment with at least some notion of control, and then carry it out, so you can actually see the results. Instead this site seems to be "regurgitate myths". e.g. http://mythbusters.js.org/workflow/boolean-conditions.html "Avoid using >= and <= unless necessary. It’s faster to use a simpler comparison." There's a trivial code example,…

it looks like they have removed that one after I (and others) left comments

Re: JS MythBusters – An optimization handbook from a high level point of view

#27

Some of these suggestions are good but some caveats: - Lookup tables- while lookup tables are great, engines might sometimes convert switch statements to lookup tables too- Chakra does this when it's advantageous to do so - Try-catch- this seems like v8 specific advice. Chakra definitely does optimize functions with try-catch in it, and I think SpiderMonkey does too - Freeing memory- setting the reference to null doe…

I vaguely remember firefox choking on try/finally but not try/catch, may have been fixed could have been a dream but in generally try can be tricky
Post reply on HN