Skip to content

Conversation

@rbuckton
Copy link
Contributor

This changes the somewhat fragile way we handled the simplification of constructor body statements when transforming super() that became even more fragile in TS 5.2. These simplifications were intended to slim down transformed constructor bodies when a temporary variable like _this may not be necessary:

// given
class C extends Base {
  constructor() {
    super();
  }
}

// without simplification
var C = (function (_super) {
    function C() {
        var _this = this;
        _this = _super.call(this) || this;
        return _this;
    }
    return C;
})(Base);

// with simplificaiton
var C = (function (_super) {
    function C() {
        return _super.call(this) || this;
    }
    return C;
})(Base);

However, when using was introduced in TS 5.2, the simplification mechanism became more complicated as the super() statements we would normally look for would be moved inside of a try..catch..finally block if the constructor contained a using declaration.

Rather than try to handle specific super() simplifications when initially visiting the constructor body, this PR instead performs these simplifications in a second pass after the initial transformation completes. This results in a mechanism that is more reliable than the prior approach as it only performs these simplifications with complete knowledge of the transformed result..

Fixes #55646
Fixes #55637

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Oct 16, 2023
@rbuckton
Copy link
Contributor Author

@typescript-bot perf test

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 16, 2023

Heya @rbuckton, I've started to run the regular perf test suite on this PR at 21a697d. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@rbuckton
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,079k (± 0.02%) 295,145k (± 0.01%) +66k (+ 0.02%) 295,098k 295,207k p=0.020 n=6
Parse Time 2.62s (± 0.92%) 2.64s (± 0.52%) ~ 2.61s 2.65s p=0.506 n=6
Bind Time 0.84s (± 1.17%) 0.84s (± 1.06%) ~ 0.83s 0.85s p=0.798 n=6
Check Time 8.07s (± 0.31%) 8.08s (± 0.22%) ~ 8.05s 8.10s p=0.463 n=6
Emit Time 7.05s (± 0.19%) 7.09s (± 0.28%) +0.04s (+ 0.61%) 7.06s 7.12s p=0.008 n=6
Total Time 18.58s (± 0.19%) 18.65s (± 0.22%) +0.07s (+ 0.36%) 18.60s 18.72s p=0.010 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 193,542k (± 1.65%) 191,631k (± 1.24%) ~ 190,642k 196,499k p=1.000 n=6
Parse Time 1.34s (± 0.82%) 1.35s (± 1.46%) ~ 1.32s 1.38s p=0.611 n=6
Bind Time 0.73s (± 0.00%) 0.73s (± 0.00%) ~ 0.73s 0.73s p=1.000 n=6
Check Time 9.13s (± 0.27%) 9.12s (± 0.30%) ~ 9.09s 9.16s p=0.629 n=6
Emit Time 2.64s (± 0.37%) 2.63s (± 0.44%) ~ 2.61s 2.64s p=0.209 n=6
Total Time 13.84s (± 0.26%) 13.83s (± 0.17%) ~ 13.80s 13.86s p=0.464 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,292k (± 0.00%) 347,355k (± 0.01%) +63k (+ 0.02%) 347,313k 347,421k p=0.005 n=6
Parse Time 2.45s (± 0.31%) 2.45s (± 0.17%) ~ 2.45s 2.46s p=1.000 n=6
Bind Time 0.94s (± 0.87%) 0.94s (± 0.55%) ~ 0.94s 0.95s p=0.114 n=6
Check Time 6.90s (± 0.49%) 6.91s (± 0.44%) ~ 6.87s 6.95s p=0.376 n=6
Emit Time 4.03s (± 0.51%) 4.04s (± 0.40%) ~ 4.02s 4.07s p=0.255 n=6
Total Time 14.32s (± 0.34%) 14.35s (± 0.19%) ~ 14.31s 14.38s p=0.260 n=6
TFS - node (v18.15.0, x64)
Memory used 302,543k (± 0.01%) 302,578k (± 0.01%) ~ 302,539k 302,637k p=0.092 n=6
Parse Time 2.01s (± 0.77%) 2.00s (± 0.42%) ~ 1.99s 2.01s p=0.078 n=6
Bind Time 1.00s (± 1.36%) 1.00s (± 1.04%) ~ 0.98s 1.01s p=0.557 n=6
Check Time 6.26s (± 0.31%) 6.27s (± 0.48%) ~ 6.24s 6.32s p=0.514 n=6
Emit Time 3.55s (± 0.58%) 3.59s (± 0.45%) +0.03s (+ 0.94%) 3.56s 3.60s p=0.022 n=6
Total Time 12.83s (± 0.34%) 12.85s (± 0.25%) ~ 12.82s 12.91s p=0.226 n=6
material-ui - node (v18.15.0, x64)
Memory used 470,501k (± 0.00%) 470,498k (± 0.00%) ~ 470,479k 470,512k p=0.423 n=6
Parse Time 2.58s (± 0.75%) 2.58s (± 0.67%) ~ 2.56s 2.60s p=1.000 n=6
Bind Time 0.99s (± 0.55%) 1.00s (± 0.89%) ~ 0.99s 1.01s p=0.341 n=6
Check Time 16.62s (± 0.34%) 16.59s (± 0.36%) ~ 16.53s 16.67s p=0.421 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.20s (± 0.34%) 20.17s (± 0.26%) ~ 20.11s 20.25s p=0.627 n=6
xstate - node (v18.15.0, x64)
Memory used 512,610k (± 0.01%) 512,649k (± 0.01%) ~ 512,579k 512,720k p=0.471 n=6
Parse Time 3.27s (± 0.30%) 3.26s (± 0.27%) ~ 3.25s 3.27s p=0.082 n=6
Bind Time 1.55s (± 0.41%) 1.55s (± 0.58%) ~ 1.54s 1.56s p=1.000 n=6
Check Time 2.86s (± 0.58%) 2.88s (± 0.69%) ~ 2.86s 2.91s p=0.171 n=6
Emit Time 0.08s (± 4.99%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=0.405 n=6
Total Time 7.76s (± 0.28%) 7.76s (± 0.26%) ~ 7.74s 7.80s p=0.935 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,372ms (± 1.62%) 2,393ms (± 1.42%) ~ 2,336ms 2,423ms p=0.229 n=6
Req 2 - geterr 5,376ms (± 1.70%) 5,339ms (± 1.42%) ~ 5,282ms 5,439ms p=0.575 n=6
Req 3 - references 327ms (± 0.63%) 330ms (± 1.71%) ~ 323ms 337ms p=0.375 n=6
Req 4 - navto 275ms (± 1.29%) 276ms (± 1.27%) ~ 270ms 280ms p=0.627 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 83ms (± 7.98%) 82ms (± 8.15%) ~ 76ms 91ms p=0.935 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,474ms (± 0.99%) 2,493ms (± 0.65%) ~ 2,466ms 2,514ms p=0.173 n=6
Req 2 - geterr 4,183ms (± 1.48%) 4,106ms (± 1.96%) ~ 4,042ms 4,210ms p=0.173 n=6
Req 3 - references 334ms (± 1.14%) 340ms (± 1.61%) ~ 333ms 345ms p=0.059 n=6
Req 4 - navto 283ms (± 0.48%) 285ms (± 0.78%) ~ 283ms 289ms p=0.145 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 79ms (± 6.33%) 82ms (± 8.53%) ~ 74ms 89ms p=0.546 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,598ms (± 0.38%) 2,581ms (± 0.50%) -18ms (- 0.67%) 2,562ms 2,598ms p=0.045 n=6
Req 2 - geterr 1,711ms (± 2.24%) 1,716ms (± 3.06%) ~ 1,638ms 1,773ms p=0.936 n=6
Req 3 - references 110ms (± 7.77%) 113ms (±10.10%) ~ 105ms 129ms p=1.000 n=6
Req 4 - navto 359ms (± 0.37%) 359ms (± 0.29%) ~ 358ms 360ms p=0.457 n=6
Req 5 - completionInfo count 2,073 (± 0.00%) 2,073 (± 0.00%) ~ 2,073 2,073 p=1.000 n=6
Req 5 - completionInfo 304ms (± 1.37%) 308ms (± 1.32%) ~ 304ms 315ms p=0.126 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 152.42ms (± 0.18%) 152.45ms (± 0.16%) ~ 151.43ms 155.17ms p=0.282 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 227.68ms (± 0.14%) 227.71ms (± 0.15%) ~ 226.63ms 231.04ms p=0.891 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 228.40ms (± 0.16%) 228.55ms (± 0.19%) +0.15ms (+ 0.07%) 226.64ms 235.53ms p=0.001 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 228.80ms (± 0.18%) 228.88ms (± 0.17%) ~ 227.25ms 234.95ms p=0.064 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

var D = /** @class */ (function (_super) {
__extends(D, _super);
function D() {
var _this = _super.call(this, 1, 2) || this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional to leave this unused variable behind? I guess it's harmless?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no. It's intentional in that the conditions for the simplification that elides var _this = isn't met. We could change the rules, in the future if necessary, but I don't want to spend too much time processing these simplifications during emit, which are primarily only to improve readability when debugging unmapped outputs, so I've generally opted for more coarse-grained rules.

@rbuckton
Copy link
Contributor Author

I'm going to make a small update to make updatePropertyName public to align with #56194

@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

@rbuckton rbuckton merged commit 8e37e4b into main Oct 24, 2023
@rbuckton rbuckton deleted the fix-55646 branch October 24, 2023 01:01
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect ES5 transpilation for try/catch + super Incorrect ES5 transpilation for 'this' usage in lambda as a constructor default parameter

4 participants