Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAllow assert to be optimized #71
Conversation
@@ -413,7 +413,11 @@ exports.assert = function (condition /*, msg1, msg2, msg3 */) { | |||
return; | |||
} | |||
|
|||
var msgs = Array.prototype.slice.call(arguments, 1); | |||
var msgs = []; | |||
for (var i = 1, il = arguments.length; i < il; ++i) { |
This comment has been minimized.
This comment has been minimized.
arb
Aug 1, 2014
Contributor
I'm not so sure about this change. I have no doubt this is faster and can be optimized, but there is probably a reason no one really does it this way and always uses the Array.prototype.slice.call
trick.
Check out this implementation. https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments. That looks like the way to go to me personally if we are trying to squeeze optimizations.
This comment has been minimized.
This comment has been minimized.
Hmm. First, doesn't the early return already void optimization? And even if the function is not optimized, what impact does this have when the condition is true? I assume none. Are we really trying to optimize when the server is about to go boom?! |
This comment has been minimized.
This comment has been minimized.
@hueniverse from looking at the deoptimization statements... this is able to be optimized with the early return from what I saw. It seemed like an easy win since we call assert so frequently. |
This comment has been minimized.
This comment has been minimized.
Ok. Can you add a comment documenting why we are not using slice() in this case? |
This comment has been minimized.
This comment has been minimized.
@hueniverse added |
Allow assert to be optimized
geek commentedAug 1, 2014
If you run hoek with --trace_opt you can see that the exports.assert isn't optimized because it calls slice on arguments:
After changing this to manually populate msgs from the arguments the function can be optimized by the optimizing compiler.