Unoptimized destructuring compilation
See original GitHub issueTypeScript 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:
- Created 7 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
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
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.
Idly curious why you’re writing the intializers this way? Why not just
var a = 1, b = 2, c = 3
?