Re:Arguments Object: Doctor Jekyll and Mister Hyde in Node.js
by IsaacSchlueter on Saturday July 16, 2011 @03:28PM
(#2771503)
> theoretically compiler could have inlined slice
> and looked one level deeper to see that.
I'd suspect that optimizing Array.prototype.slice.call(arguments, n, m) at the v8 level would yield pretty significant gains, even if no other arguments-object abuse was supported intelligently.For almost any complicated operation on the arguments, your first step is to convert it (or part of it) to a true Array. Most libraries do that using Array.prototype.slice, in my experience.
What optimizing compiler tries to do is to avoid creating arguments object and rewrite simple uses (simple is defined in the referenced post) to operate directly on the stack instead of creating and passing around real object. I should probably do yet another post about that but now with some assembly (but my battery is running low atm) :-)
Doing something like:
this use is not simple so compiler just gives up. But theoretically compiler could have inlined slice and looked one level deeper to see that.