V8 Optimization Killers
github.com
V8 Optimization Killers
1–10 of 88 posts
Re: V8 Optimization Killers
#2Re: V8 Optimization Killers
#3Re: V8 Optimization Killers
#4Title should probably be "V8 Optimization Killers".
Re: V8 Optimization Killers
#5 function doesntLeakArguments() {
var args = new Array(arguments.length);
for(var i = 0; i
becomes: function doesntLeakArguments() {
var len = arguments.length;
var args = new Array(len);
for(var i = 0; i
And also, if you've got a switch statement with more than 128 cases, you've probably got bigger problems on your hands than v8 optimizations.I see some things in here that I can start switching to immediately for some of my node modules.
Re: V8 Optimization Killers
#6An excellent overview! A bit worrying that using an object as a hash table and iterating over its keys using ForIn would prevent optimization - I had always thought that this was a common use case that would be well-supported by the optimizer! I suppose in that case, if you need fast reads of all keys and can afford slower writes, you could maintain an array of the keys at insertion time and just loop through that?
var keys = Object.keys(obj),
length = keys.length,
key, i;
for (i = 0; i
While this is not exactly the same as for..in, it usually behaves how you'd expect and is significantly faster for a couple of reasons:1. In a for..in loop the engine must keep track of the keys already iterated over, whereas in the fast version we can simply increment a counter and do a fast array lookup.
2. It's possible to add properties to the object that you're iterating within the body of the for..in statement, and these will be iterated too. Doing such a thing is obviously very rare but it's the kind of edge case the JS engine must keep track of.
Re: V8 Optimization Killers
#7Really great! Some notes that popped out for me are that to always cache the .length property for any array or arguments: function doesntLeakArguments() { var args = new Array(arguments.length); for(var i = 0; i becomes: function doesntLeakArguments() { var len = arguments.length; var args = new Array(len); for(var i = 0; i And also, if you've got a switch statement with more than 128 cases, you've probably got bigge…
Re: V8 Optimization Killers
#8Re: V8 Optimization Killers
#9Title should probably be "V8 Optimization Killers".
I'm really sick of these recent JavaScript performance related posts that only talk about V8.
Re: V8 Optimization Killers
#10Really great! Some notes that popped out for me are that to always cache the .length property for any array or arguments: function doesntLeakArguments() { var args = new Array(arguments.length); for(var i = 0; i becomes: function doesntLeakArguments() { var len = arguments.length; var args = new Array(len); for(var i = 0; i And also, if you've got a switch statement with more than 128 cases, you've probably got bigge…