question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimize rest arguments.

See original GitHub issue

The 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:

https://bugzilla.mozilla.org/show_bug.cgi?id=1056446

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
begincalendarcommented, Dec 12, 2017

As asked by @andy-ms (here), what are the use-cases for having unused rest parameters?

0reactions
duncanmakcommented, Sep 24, 2014

Just a reminder, #518 fixes this issue. When will it get merged into master?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found