LXJS 2013 - Vyacheslav Egorov - Performance and benchmarking
Why Stack Overflow recommends it
Stack Overflow users link it when answering JavaScript performance questions where a microbenchmark or jsperf test is misleading because the engine optimises the code away.
Recommended by 6 people across 6 different months, 2013 to 2017.
What it is
A LXJS 2013 conference talk by Vyacheslav Egorov (@mraleph), a V8 engineer, on JavaScript performance and benchmarking. It explains how JIT compilers optimise code and why naive microbenchmarks often measure nothing real.
What people said
Recommends Mathias Bynens · 2013-10 · Stack Overflow · on “performance of '==' vs '===' (jsperf)”
== vs. === is not going to make a real-world difference in your code’s performance. This is a microbenchmark. Check out this presentation by @mraleph, explaining why microbenchmarks are evil and should be avoided: [this video] He explains why tests like the one you linked to are basically useless, as engines optimize things like this away.
Recommends Dimitar Christoff · 2013-11 · Stack Overflow · on “Mootools Selectors $ or $$. Which is more performant”
this is not a good test. dom is too simple, you are not really making it work. you are not caching the element browsers are really smart now when benchmarking, you really need to view [this video] - also, look at your fiddle dom = `.toggler` is not an id, it's a `class="toggler"` for it to make sense.
Recommends Rafael Xavier · 2014-06 · Stack Overflow · on “How do you performance test JavaScript code?”
Quick answer On jQuery (more specifically on Sizzle), we use this [LINK] (checkout master and open speed/index.html on your browser), which in turn uses benchmark.js [LINK] . This is used to performance test the library. Long answer If the reader doesn't know the difference between benchmark, workload and profilers, first read some performance testing foundations on the "readme 1st" section of spec.org [LINK] . This is for system testing, but understanding this foundations will help JS perf testing as well. Some highlights: What is a benchmark? A benchmark is "a standard of measurement or evaluation" (Webster’s II Dictionary). A computer benchmark is typically a computer program that perform
Recommends yellowsir · 2016-04 · Stack Overflow · on “let vs var performance in nodejs and chrome”
i can't tell you more but as mentiont in this video (very good), you need smarter code to test this. [this video] the compiler will to magic stuff with your code and might even ereas the loop if you don't use i and the loop is empty
Recommends Nick Long · 2016-06 · Stack Overflow · on “JS: Assigning a variable in the parent scope of a closure costs performance. Why?”
In the example without the closure any decent Javascript engine will realise that the variables within the function are initialised but never read before going out of scope and thus can be removed without affecting the output of the function. In the example with the closure the variables remain in scope and thus can't be optimised out. This talk explains in depth some of the optimisations JIT Javascript compilers make: [this video]
Recommends Web_Designer · 2017-06 · Stack Overflow · on “Performance of Google chrome vs nodejs (v8)?”
In your simple example the loop ultimately does nothing but change the variable `i` from 0 to several million. The V8 engine's JIT compiler will optimize parts like this and may not even run the loop at all if it can get the same result. As you can see, this will depend on the environment the JS is run in. This is a relevant JS talk on performance and benchmarking: [this video]
Cites Dimitar Christoff · 2013-11 · Stack Overflow · on “Mootools Selectors $ or $$. Which is more performant”
performance of selectors will differ between browsers significantly. eg. with querySelector and querySelectorAll (QSA) vs without. When without QSA, with getElementsByClassName or without. the amount of work that the selector engine needs to do will vary. you can write this differently. 3 ways to do so, not just 2: 1. $('accountDetailsTable').getElements('.toggler') anatomy of the above is: get element (1 call). call method getElements from element prototype (or element directly in old IE) look for all childNodes that match the class selector this will be consistent in browsers in that it gets a root node and calls methods off it. if no QSA, it will go to getElementsByClassName or walk all c
Cites shennan · 2014-07 · Stack Overflow · on “JS: Why Is This Slower? It Shouldn't Test Other OR Conditions But It Does?”
@cookiemonster We agree on the answer... that the *test* is a *pointless one* [this video] . But that doesn't mean the *question* is a pointless one... is what I'm trying to say.
Cites Bergi · 2014-07 · Stack Overflow · on “JS: Why Is This Slower? It Shouldn't Test Other OR Conditions But It Does?”
@RainingChain: Why do you think this is non-trivial? The compiler always is smarter [this video] . Unless your code looks too dumb to be optimizable.
Cites Trott · 2015-04 · Stack Overflow · on “does size of argument in a javascript function affects its performance?”
JavaScript passes arrays and objects to functions by passing a copy of the reference to the array/object, so it is likely to be fine to pass the whole thing. Just know that if you mutate it in the function, those changes will affect your original array/object! If this is browser code and not server (e.g., Node.js) code, you can test with jsperf.com [LINK] . Just be careful. It's easy to do JS benchmarks wrong! [this video]