> from a high level point of view Many of the examples I looked at were very granular and specific, but didn't have much explanation. Does high level point of view really mean brief and without elaboration? From a high level on JS optimization I would like to see more emphasis on which considerations are most likely to have the biggest impact on my code. Throwing everything in together as if they were all equal seems…
JS MythBusters – An optimization handbook from a high level point of view
11–20 of 27 posts
Re: JS MythBusters – An optimization handbook from a high level point of view
#12How many of these optimizations are just limited to V8? I swear I've heard somewhere that the try/catch limitation is specific to V8, and that other engines don't have that problem. Am I mistaken? EDIT: Also, this page is very difficult to read. I have a laptop with a great screen and the lack of contrast is annoying.
Re: JS MythBusters – An optimization handbook from a high level point of view
#13Some 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…
Carakan doesn't either. But given that nowadays affects some old TVs (but still newish, I doubt most people replace TVs that often…) and Opera Mini's limited JS support… Yeah, okay, that doesn't matter. :)
Re: JS MythBusters – An optimization handbook from a high level point of view
#14Instead 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, and then absolutely no evidence to support the claim. No benchmarks, nothing.
Re: JS MythBusters – An optimization handbook from a high level point of view
#15Some 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…
> Try-catch- this seems like v8 specific advice. Chakra definitely does optimize functions with try-catch in it, and I think SpiderMonkey does too http://gs.statcounter.com/ certainly suggests that specifically optimizing for Chrome/V8 will benefit the majority of users (58% not including mobile, 50% including mobile). As with all statistics, take with a grain of salt.
Re: JS MythBusters – An optimization handbook from a high level point of view
#16> Avoid using >= and Is this an elaborate troll?
Re: JS MythBusters – An optimization handbook from a high level point of view
#17Some 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…
This one also seems a bit iffy to me, depending on the stage of compilation, how often this code runs, how much information the engine is able to collect, and the size of your table. The initial unoptimized property lookups will likely be slower than if/else statements, and the engine may end up optimizing them with inline caches, which are essentially a chain of if/else comparisons and jumps between dynamically generated code stubs.
> Try-catch
Yep, SpiderMonkey does optimize this case.
Re: JS MythBusters – An optimization handbook from a high level point of view
#18One 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,…
[0] https://dxr.mozilla.org/mozilla-central/source/js/src/jit/Io...
Re: JS MythBusters – An optimization handbook from a high level point of view
#19I think this is not well researched enough. There doesn't appear to be any thought put into optimization vs. readability, and when the optimization improves enough speed to justify the poor readability.
Also, when Google or whoever decides to update the engine and compiles things differently, these hacks might become less efficient than just following best practices.
Re: JS MythBusters – An optimization handbook from a high level point of view
#20One 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's just some random opinions about optimizations you most likely don't need. Who cares if something is barely faster? If the slower way is a lot more readable, I'm opting for that.