4 ms·
V8 crankshaft vs. arguments object
- doublerebel 11y ago...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?
- phpnode 11y agoIt would not be a web compatible change so will never happen. Too much code relies on them being different.
- doublerebel 11y agoThat doesn't make sense. Plenty of features from ES6 and 7 on the server and other platforms have steamed ahead despite browser adoption.
- phpnode 11y agoThings regularly fail to make it due to web compat, e.g. Array.prototype.contains() was rejected.
- hajile 11y agoAlmost all ES5.1 code will run on a browser that implements ES2015. There are subtle breakages like there were when moving from ES3 to ES5.1, but affected code is rare (and probably bad anyway). If `arguments` were changed, it would break huge swaths of the web rather than a couple sites. While it would be nice to require everyone to re-write their website code, the cost would probably be in the hundreds of billions of dollars. The pragmatic choice is to leave it in place and discourage it's use. Maybe it can be deprecated in a couple decades.
- inglor 11y agoIf 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 11y agoYep. If you need an unknown number of things put them in an array. The arguments object is just too complicated for perf critical code.
- exogen 11y agoIs 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.
- roflchoppa 11y agoman i got excited about crankshafts, i wanted to see it damage something...