
V8 crankshaft vs. arguments object - luu
http://mrale.ph/blog/2015/11/02/crankshaft-vs-arguments-object.html
======
exogen
Is it common for people to enable these deoptimization messages (e.g.
"Unsupported phi use of arguments") somehow when they're optimizing code? I
know there are linters that might warn you about some cases, and the Chrome
dev tools show a little hazard symbol next to deoptimized functions... is
there a more streamlined workflow where you see deoptimization messages from
the engine in a nice way (instead of what I'm expecting to see by enabling
some V8 flags, which is a verbose jumbled mess)?

Off topic: The design decision in ES2015 to have lexical `arguments` [1] in
arrow functions completely baffled me and my coworkers. It completely breaks
the contract that most people think arrow functions abide by, which is that
it's a simple transformation to `function() { ... }.bind(this)`.

    
    
        function foo() {
          const bar = (a, b, c) => {
            console.log([a, b, c]);
            console.log(arguments);
          };
          bar('a', 'b', 'c');
        }
        
        > foo('x', 'y', 'z');
        ['a', 'b', 'c']
        { '0': 'x', '1': 'y', '2': 'z' }
    

In realistic cases it's common to switch to arrow functions just for their
brevity or to capture `this` – and then all of a sudden things aren't doing
what you expect. This has already bitten me several times.

[1] [https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Refe...](https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#Lexical_arguments)

~~~
chrisseaton
I think any kind of visualisation of VMs like you're suggesting (little hazard
symbol next to deoptimised methods) is very complicated in practice.

A method could be deoptimised once early, but then not again when the program
is actually running in your inner loop. In which case you don't care it was
deoptimised.

In the optimising implementation of Ruby I work on, we are aggressive about
splitting (multiple versions of a method so they can collect independent
profiling data) and that means one version of a method may be deoptimised, but
others aren't. How do you show that when you are looking at a single copy of
the source code?

~~~
netghost
Chrome Canary at least is now showing deopt next to functions in the profiler.

------
doublerebel

        ...arguments object not being an Array is yet another
        JavaScript wart that causes nothing but special cases
        and complexity in optimization pipelines...
    

So, why can't we make `arguments` into an immutable Array for ES7? Is there
any compiler advantage to keeping the special case?

~~~
inglor
If it was possible, we'd remove `arguments` altogether in favor of rest
parameters. There is absolutely no reason to use `arguments` in ES2015 anyway.

~~~
gefh
Yep. If you need an unknown number of things put them in an array. The
arguments object is just too complicated for perf critical code.

------
roflchoppa
man i got excited about crankshafts, i wanted to see it damage something...

