Micro optimization - Second Attempt #841

merged 2 commits into from Dec 6, 2012

3 participants


The intent is to do a quick review across the core modules to try to optimize them for V8, specially the low hanging fruits. So far, we have two things we want to optimize:

  • "delete" is evil in V8, avoid the use of delete on objects.
    for more details, check this gist:

  • "try/catch" is slow, avoid the use of it when possible.

PR #778

Yahoo Inc. member

Just to be pedantic, your gist suggests that delete isn't the problem, but if (obj.member_doesnt_exist) is the problem.


@drewfish the gist is just a simple demostration, I do have a test based on benchmark.js that reflects the same though.

Now, about the delete vs if, the problem here is the V8 low level optimizations. The if is in every test, but only on the object that was transformed using delete the if will take longer. Apparently, by using delete, V8 will change the type of object in memory, which affects the members resolution.

Yahoo Inc. member


@caridy caridy merged commit b254d13 into yahoo:develop Dec 6, 2012

1 check passed

Details default The Travis build passed

@caridy actually delete removes the key, so javascript must check the prototype chain. by assigning something falsey as a value of the key, the falsey check is immediate. I wouldn't say delete is evil, but +1 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment