Micro optimization - Second Attempt #841

Merged
merged 2 commits into from Dec 6, 2012

3 participants

@caridy

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:
    https://gist.github.com/4126067

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

PR #778

@drewfish
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.

@caridy

@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.

@drewfish
Yahoo Inc. member

+1

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

1 check passed

Details default The Travis build passed
@isao

@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