Optimization killers: popping an argument by decrementing `arguments.length`?

44 views
Skip to first unread message

Alex Goldsmith

unread,
Feb 8, 2017, 4:29:28 AM2/8/17
to v8-users
Howdy.

I was just reading through the Optimization Killers article on the Bluebird wiki, trying to work out whether the following would be optimized:

function get(/* ...k, j, i */) {
   
const a = arguments, l = a.length, n = l - 1
   switch (l) {
      case 0: return this
      case 1: return this[a[n]]
      default: return get.apply(this[a[a.length = n]], a) // a.length = n = a.length - 1
   }
}

console
.log(get.call({x:{y:{z:'!!!'}}}, 'z','y','x')) // => "!!!"


Shedding an argument in this way isn't really discussed (anywhere that I can find), but it seems like it should be okay (at least it doesn't appear to be leaking).

Any insight would be highly appreciated. Thanks in advance!


Ben Noordhuis

unread,
Feb 8, 2017, 6:09:53 AM2/8/17
to v8-users
Start node or d8 with --trace_opt and it will tell you. My bet is
that you'll see a "Bad value context for arguments value" warning; V8
really doesn't like it when you modify arguments objects.

Jason Zoo

unread,
Feb 21, 2017, 1:56:51 AM2/21/17
to v8-users
Hi,Why I use `d8 --trace_opt` output nothing?  My v8 version is 5.8.

Ben Noordhuis

unread,
Feb 21, 2017, 2:19:11 AM2/21/17
to v8-users
On Tue, Feb 21, 2017 at 7:56 AM, Jason Zoo <zjc...@gmail.com> wrote:
> Hi,Why I use `d8 --trace_opt` output nothing? My v8 version is 5.8.

Try adding --trace_deopt as well.

Jason Zoo

unread,
Feb 21, 2017, 5:49:47 AM2/21/17
to v8-users
also nothing. 

Jason Zoo

unread,
Feb 22, 2017, 6:44:03 AM2/22/17
to v8-users
add --trace as well
Reply all
Reply to author
Forward
0 new messages