3 ms·
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
by exogen 11y ago
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/Reference/Functions/Arrow_functions#Lexical_arguments https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- phpnode 11y agoIRHydra2 is pretty good for it but has a learning curve. There is really no need for the arguments object in a world with default and rest parameters, and it has always been an obstacle to performance, so I'm glad arrow functions don't use it.
- exogen 11y agoIt's not so much that arrow functions "don't use it" that I'm complaining about but rather that they change the meaning and thus have confusing results. Also, changing that example to use rest parameters: function foo() { const bar = (...abc) => { console.log(abc); console.log(arguments); }; bar('a', 'b', 'c'); } SyntaxError: 'arguments' object may not be used in conjunction with a rest parameter ...which, okay, hmmm, it's sort of attempting to help me avoid confusion here. But that...was not what I was expecting. It's really weird that all of a sudden, just by adding a rest parameter to my function, a reference to `arguments` becomes invalid syntax.
- bsimpson 11y agoWhere are you finding that? This is what I get from Chrome: foo(1, 2, 3) // ["a", "b", "c"] // [1, 2, 3] And this is what I get from https://babel.io/repl https://babel.io/repl : 'use strict'; function foo() { var _arguments = arguments; var bar = function bar() { for (var _len = arguments.length, abc = Array(_len), _key = 0; _key < _len; _key++) { abc[_key] = arguments[_key]; } console.log(abc); console.log(_arguments); }; bar('a', 'b', 'c'); }
- exogen 11y agoFirefox. Chrome has not released support for rest params yet (it's in beta).
- chrisseaton 11y agoI 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 11y agoChrome Canary at least is now showing deopt next to functions in the profiler.
- hajile 11y agoIn fat arrow functions, the `this` works the same as `arguments`. Both of them use the closest scope/closure which has the variable defined. The `.bind(this)` is a good mental approximation, but is actually a little different because the inner scope doesn't actually create ANY `this` variable. Not having `arguments` isn't a mistake because `...rest` parameters are allowed and are much better in every way.