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.

Unoptimized destructuring compilation

See original GitHub issue

TypeScript Version: 2.0

Code

// source ts code
let i = 1000;
while (i--) {
  let [a, b, c] = [1, 2, 3];
}

Expected behavior:

// compiled by babel
var i = 1000;
while (i--) {
  var a = 1;
  var b = 2;
  var c = 3;
}

Actual behavior:

// compiled by tsc
var i = 1000;
while (i--) {
    var _a = [1, 2, 3], a = _a[0], b = _a[1], c = _a[2];
}

On each iteration tsc creates new unnecessary array _a.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aluanhaddadcommented, Oct 22, 2016

I like how the output always matches the syntax being transformed, it is nicely predictable. Also, if this were added, I would want to disable it during development. I would only enable it when creating a production build because there is likely to be a performance penalty for these kinds of heuristic optimizations during transpilation. It may be small, but I would want to disable it.

Unfortunately, just the notion of toggleable optimizations would introduce a lot of additional, and in my mind unnecessary complexity into the language. I real don’t like the idea of having TS dev and TS prod modes as these are in the domain of other tools.

You could argue that I am being hyperbolic by even hinting at this but I can imagine the issues requesting potential optimization x, or y, which breaks z that would crop up overnight.

1reaction
RyanCavanaughcommented, Oct 21, 2016

Idly curious why you’re writing the intializers this way? Why not just var a = 1, b = 2, c = 3 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unoptimized Code Generation
Emphasis on UNOPTIMIZED. • Do simplest possible thing for now ... Routines for Destructuring Program. Representation destruct(n) ... Basic Compilation Tasks ...
Read more >
Suggestion Backlog Slog, 11/14/2016 #12241 - GitHub
Unoptimized destructuring compilation #11779 Optimize emit for destructuring of array. Community / Accepting PR for only the case of an ...
Read more >
Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >
How to destructure enum when de/serializing yaml or json ...
cargo run Compiling enum_unpack v0.1.0 (.../enum_unpack) Finished dev [unoptimized + debuginfo] target(s) in 0.66s Running ...
Read more >
On the Cleverness of Compilers - Hacker News
"Thankfully" the C++ of the game took so long to compile that we were already ... unoptimized code generation for quick turnaround time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

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