Optimize rest arguments.
See original GitHub issueThe TypeScript compiler generates the following code for rest arguments:
function foo(x, y, z, ...rest) {
return;
}
function foo(x, y, z) {
var rest = [];
for (var i = 0; i < arguments.length - 3; i++) {
rest[i] = arguments[i + 3];
}
return;
}
Although rest
is unused in the body of the function, JS engines can’t easily dead code eliminate the allocation of the rest
array and the subsequent for loop due to the possibility of Array.prototype being mutated:
Object.defineProperty(Array.prototype, 42, { set: function() { alert(this[41]); }});
It’s much easier for the TypeScript compiler to avoid emitting this code when it is not necessary.
See more details:
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
javascript - Do rest parameters allow for optimization?
The Managing arguments section in Bluebird's article on Optimization killers states that: The arguments object must not be passed or leaked ...
Read more >Rest parameters and arguments object optimization plan
This document describes the design and implementation of rest parameters and the Arguments Exotic Objects in the TurboFan compiler and the ...
Read more >8 Tips for Optimizing an API
Want to know how optimizing an API will enable better performance? These tips will have you on your way to getting the most...
Read more >Rest parameters - JavaScript - MDN Web Docs
The rest parameter syntax allows a function to accept an indefinite number of arguments as an array, providing a way to represent variadic ......
Read more >Faster JavaScript calls
In the over-application case, the remaining arguments can be accessed by using the rest parameter and the arguments property, or they are simply ......
Read more >Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As asked by @andy-ms (here), what are the use-cases for having unused rest parameters?
Just a reminder, #518 fixes this issue. When will it get merged into master?