Skip to content

Use control flow to type CommonJS exports #42751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Feb 11, 2021

This allows us to read our own output, plus the times when people manually write exactly the same pattern. It may also allow other patterns in the wild, although I need to look at the user test output to find out if that's the case.

Implementation notes

  1. Control flow works with any number of assignments, even though the common case is one assignment from undefined and another from the actual value.
  2. I add a endFlowNode property to source files in order to run control flow on the statements of a source file. Then I use this node to get the control flow type of an export from outside the file, when it's imported.

Fixes #40555

This allows us to read our own output, plus the times when people
manually write exactly the same pattern.

Fixes #40555
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Feb 11, 2021
@weswigham
Copy link
Member

I couldn't think of a simple way remove undefined from the type

Feels like something we could use CFA for, like how we track initializers for class properties through a constructor body.

@sandersn
Copy link
Member Author

sandersn commented Feb 11, 2021

The problem with control flow is that it doesn't normally persist across aliases. It doesn't actually matter what the type of exports.x is inside the defining file -- it only matters when you const { x } = require('./test'). I wonder if there's a way for the import alias to provide a different type than the export alias in this case.

Edit: To use control flow, maybe I could create a structure to query and capture the type at the bottom of the file. Not sure how that would work either.

@weswigham
Copy link
Member

I mean, analogously, the externally visible type of a constructor property is the one determined by CFA at the end of the conctructor, yeah? Not the union of the constructor-assigned types.

@weswigham
Copy link
Member

To use control flow, maybe I could create a structure to query and capture the type at the bottom of the file.

Yeah; if we don't already have a CFA node at the end of the file (I think we should, though), you'd need to add one like we did for constructor properties.

1. Could probably use a *lot* more tests.
2. getTypeOfAlias redoes some work from resolveAlias because it needs to
not resolve the alias completely, just to its export.
@sandersn sandersn changed the title Allow redeclaring CommonJS alias with initial undefined Use control flow to type CommonJS exports Feb 13, 2021
@@ -26429,7 +26448,10 @@ namespace ts {
// accessor, or optional method.
const assignmentKind = getAssignmentTargetKind(node);
if (assignmentKind === AssignmentKind.Definite ||
prop && !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.Accessor)) && !(prop.flags & SymbolFlags.Method && propType.flags & TypeFlags.Union)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Only change here is to exempt isDuplicatedCommonJSExport so that it falls through to the autoType case below

@@ -8359,7 +8374,10 @@ namespace ts {
}

function getFlowTypeOfProperty(reference: Node, prop: Symbol | undefined) {
const initialType = prop && (!isAutoTypedProperty(prop) || getEffectiveModifierFlags(prop.valueDeclaration) & ModifierFlags.Ambient) && getTypeOfPropertyInBaseClass(prop) || undefinedType;
Copy link
Member Author

Choose a reason for hiding this comment

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

No changes here, I just couldn't read it otherwise

@sandersn
Copy link
Member Author

This is a much bigger change, so

  1. It needs more tests.
  2. It needs performance testing.
  3. I need to see if I can stop re-doing resolveAlias work in getTypeOfAlias.

function a() { }
exports.apply()
~~~~~~~~~~~~~
!!! error TS2722: Cannot invoke an object which is possibly 'undefined'.
Copy link
Member

Choose a reason for hiding this comment

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

Oh that's nice. 👍

@sandersn
Copy link
Member Author

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 16, 2021

Heya @sandersn, I've started to run the perf test suite on this PR at 046bed9. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..42751

Metric master 42751 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 345,845k (± 0.03%) 345,846k (± 0.02%) +1k (+ 0.00%) 345,662k 346,051k
Parse Time 1.92s (± 0.45%) 1.91s (± 0.53%) -0.01s (- 0.47%) 1.89s 1.93s
Bind Time 0.82s (± 0.54%) 0.82s (± 0.68%) 0.00s ( 0.00%) 0.81s 0.84s
Check Time 4.97s (± 0.56%) 5.02s (± 0.51%) +0.05s (+ 1.01%) 4.97s 5.08s
Emit Time 5.25s (± 0.70%) 5.26s (± 1.05%) +0.01s (+ 0.25%) 5.17s 5.43s
Total Time 12.96s (± 0.37%) 13.01s (± 0.53%) +0.05s (+ 0.40%) 12.85s 13.14s
Compiler-Unions - node (v10.16.3, x64)
Memory used 214,406k (± 0.07%) 214,478k (± 0.02%) +72k (+ 0.03%) 214,394k 214,619k
Parse Time 0.78s (± 0.98%) 0.78s (± 0.61%) +0.00s (+ 0.26%) 0.77s 0.79s
Bind Time 0.49s (± 0.74%) 0.50s (± 1.24%) +0.00s (+ 1.01%) 0.48s 0.51s
Check Time 10.65s (± 0.82%) 10.62s (± 0.52%) -0.03s (- 0.28%) 10.52s 10.73s
Emit Time 2.33s (± 1.19%) 2.31s (± 1.22%) -0.02s (- 0.69%) 2.24s 2.35s
Total Time 14.26s (± 0.55%) 14.21s (± 0.52%) -0.04s (- 0.29%) 14.03s 14.34s
Monaco - node (v10.16.3, x64)
Memory used 355,322k (± 0.03%) 355,307k (± 0.02%) -15k (- 0.00%) 355,088k 355,424k
Parse Time 1.54s (± 0.58%) 1.55s (± 0.43%) +0.00s (+ 0.19%) 1.53s 1.56s
Bind Time 0.72s (± 0.69%) 0.72s (± 0.94%) 0.00s ( 0.00%) 0.72s 0.75s
Check Time 5.12s (± 0.61%) 5.18s (± 0.55%) +0.06s (+ 1.23%) 5.13s 5.27s
Emit Time 2.80s (± 0.77%) 2.78s (± 0.50%) -0.02s (- 0.75%) 2.75s 2.82s
Total Time 10.19s (± 0.48%) 10.23s (± 0.32%) +0.04s (+ 0.43%) 10.15s 10.30s
TFS - node (v10.16.3, x64)
Memory used 308,120k (± 0.02%) 308,247k (± 0.04%) +127k (+ 0.04%) 307,995k 308,653k
Parse Time 1.21s (± 0.41%) 1.20s (± 0.69%) -0.00s (- 0.08%) 1.19s 1.23s
Bind Time 0.68s (± 0.85%) 0.68s (± 0.59%) -0.00s (- 0.29%) 0.67s 0.69s
Check Time 4.59s (± 0.47%) 4.61s (± 0.36%) +0.02s (+ 0.54%) 4.58s 4.64s
Emit Time 2.94s (± 1.21%) 2.93s (± 1.52%) -0.01s (- 0.24%) 2.87s 3.07s
Total Time 9.41s (± 0.40%) 9.43s (± 0.58%) +0.02s (+ 0.22%) 9.37s 9.59s
material-ui - node (v10.16.3, x64)
Memory used 495,587k (± 0.01%) 495,712k (± 0.01%) +125k (+ 0.03%) 495,571k 495,873k
Parse Time 1.97s (± 0.56%) 1.97s (± 0.50%) +0.00s (+ 0.10%) 1.95s 1.99s
Bind Time 0.65s (± 0.61%) 0.65s (± 0.62%) -0.00s (- 0.31%) 0.64s 0.66s
Check Time 13.90s (± 0.43%) 14.04s (± 0.73%) +0.14s (+ 0.97%) 13.89s 14.38s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.53s (± 0.38%) 16.66s (± 0.65%) +0.13s (+ 0.81%) 16.50s 17.03s
Angular - node (v12.1.0, x64)
Memory used 323,271k (± 0.10%) 323,313k (± 0.10%) +42k (+ 0.01%) 322,017k 323,589k
Parse Time 1.90s (± 0.52%) 1.90s (± 0.67%) +0.00s (+ 0.11%) 1.88s 1.93s
Bind Time 0.80s (± 1.10%) 0.80s (± 0.72%) 0.00s ( 0.00%) 0.79s 0.81s
Check Time 4.85s (± 0.66%) 4.97s (± 1.02%) +0.12s (+ 2.48%) 4.90s 5.11s
Emit Time 5.42s (± 0.77%) 5.43s (± 0.71%) +0.01s (+ 0.13%) 5.35s 5.55s
Total Time 12.97s (± 0.42%) 13.10s (± 0.52%) +0.13s (+ 0.98%) 13.01s 13.33s
Compiler-Unions - node (v12.1.0, x64)
Memory used 199,815k (± 0.09%) 199,891k (± 0.06%) +76k (+ 0.04%) 199,487k 200,008k
Parse Time 0.77s (± 0.47%) 0.76s (± 0.90%) -0.00s (- 0.13%) 0.75s 0.78s
Bind Time 0.50s (± 0.80%) 0.50s (± 0.66%) +0.00s (+ 0.20%) 0.49s 0.51s
Check Time 9.69s (± 0.92%) 9.70s (± 0.96%) +0.02s (+ 0.20%) 9.53s 9.91s
Emit Time 2.34s (± 1.22%) 2.34s (± 1.26%) +0.00s (+ 0.13%) 2.25s 2.39s
Total Time 13.29s (± 0.68%) 13.31s (± 0.69%) +0.02s (+ 0.16%) 13.16s 13.52s
Monaco - node (v12.1.0, x64)
Memory used 337,417k (± 0.01%) 337,528k (± 0.02%) +111k (+ 0.03%) 337,338k 337,726k
Parse Time 1.53s (± 0.87%) 1.52s (± 0.39%) -0.01s (- 0.59%) 1.51s 1.54s
Bind Time 0.70s (± 0.70%) 0.70s (± 0.57%) -0.00s (- 0.43%) 0.69s 0.71s
Check Time 4.90s (± 0.46%) 4.94s (± 0.51%) +0.04s (+ 0.82%) 4.90s 5.02s
Emit Time 2.85s (± 0.74%) 2.84s (± 0.71%) -0.01s (- 0.42%) 2.81s 2.91s
Total Time 9.99s (± 0.44%) 10.01s (± 0.40%) +0.02s (+ 0.17%) 9.92s 10.09s
TFS - node (v12.1.0, x64)
Memory used 292,388k (± 0.02%) 292,346k (± 0.02%) -42k (- 0.01%) 292,157k 292,478k
Parse Time 1.23s (± 0.71%) 1.22s (± 0.53%) -0.01s (- 0.81%) 1.21s 1.23s
Bind Time 0.65s (± 0.80%) 0.65s (± 1.12%) +0.00s (+ 0.46%) 0.64s 0.67s
Check Time 4.51s (± 0.39%) 4.53s (± 0.41%) +0.02s (+ 0.47%) 4.50s 4.57s
Emit Time 2.94s (± 1.58%) 2.90s (± 0.86%) -0.04s (- 1.29%) 2.86s 2.95s
Total Time 9.33s (± 0.61%) 9.31s (± 0.40%) -0.03s (- 0.28%) 9.23s 9.39s
material-ui - node (v12.1.0, x64)
Memory used 472,380k (± 0.09%) 472,744k (± 0.07%) +364k (+ 0.08%) 471,847k 473,055k
Parse Time 1.99s (± 0.37%) 2.00s (± 0.62%) +0.01s (+ 0.35%) 1.98s 2.03s
Bind Time 0.65s (± 1.35%) 0.64s (± 0.77%) -0.01s (- 2.15%) 0.62s 0.64s
Check Time 12.57s (± 0.78%) 12.50s (± 0.79%) -0.07s (- 0.56%) 12.33s 12.69s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.22s (± 0.65%) 15.14s (± 0.66%) -0.08s (- 0.51%) 14.96s 15.31s
Angular - node (v14.15.1, x64)
Memory used 322,044k (± 0.01%) 322,034k (± 0.00%) -10k (- 0.00%) 322,009k 322,076k
Parse Time 1.91s (± 0.55%) 1.91s (± 0.55%) -0.00s (- 0.16%) 1.89s 1.93s
Bind Time 0.85s (± 0.78%) 0.85s (± 0.72%) -0.00s (- 0.23%) 0.84s 0.86s
Check Time 4.84s (± 0.48%) 4.92s (± 0.20%) +0.08s (+ 1.61%) 4.90s 4.94s
Emit Time 5.48s (± 0.61%) 5.47s (± 0.43%) -0.01s (- 0.13%) 5.42s 5.52s
Total Time 13.08s (± 0.21%) 13.15s (± 0.25%) +0.07s (+ 0.53%) 13.10s 13.23s
Compiler-Unions - node (v14.15.1, x64)
Memory used 200,506k (± 0.58%) 200,753k (± 0.65%) +248k (+ 0.12%) 199,082k 202,909k
Parse Time 0.79s (± 0.46%) 0.80s (± 0.62%) +0.00s (+ 0.25%) 0.79s 0.81s
Bind Time 0.53s (± 0.63%) 0.53s (± 0.84%) -0.00s (- 0.38%) 0.52s 0.54s
Check Time 9.69s (± 0.50%) 9.66s (± 0.38%) -0.04s (- 0.37%) 9.59s 9.73s
Emit Time 2.35s (± 1.36%) 2.35s (± 1.63%) +0.00s (+ 0.13%) 2.29s 2.44s
Total Time 13.36s (± 0.47%) 13.33s (± 0.49%) -0.03s (- 0.25%) 13.21s 13.48s
Monaco - node (v14.15.1, x64)
Memory used 336,847k (± 0.01%) 336,870k (± 0.01%) +23k (+ 0.01%) 336,829k 336,905k
Parse Time 1.56s (± 0.73%) 1.55s (± 0.26%) -0.01s (- 0.45%) 1.54s 1.56s
Bind Time 0.73s (± 0.79%) 0.73s (± 0.55%) -0.00s (- 0.14%) 0.72s 0.74s
Check Time 4.86s (± 0.46%) 4.90s (± 0.58%) +0.04s (+ 0.80%) 4.84s 4.99s
Emit Time 2.91s (± 0.38%) 2.91s (± 0.58%) -0.00s (- 0.00%) 2.87s 2.94s
Total Time 10.05s (± 0.31%) 10.08s (± 0.32%) +0.03s (+ 0.34%) 10.04s 10.19s
TFS - node (v14.15.1, x64)
Memory used 291,527k (± 0.01%) 291,569k (± 0.01%) +43k (+ 0.01%) 291,525k 291,607k
Parse Time 1.24s (± 0.97%) 1.24s (± 0.97%) +0.00s (+ 0.24%) 1.22s 1.27s
Bind Time 0.69s (± 0.89%) 0.69s (± 1.02%) -0.00s (- 0.29%) 0.68s 0.71s
Check Time 4.48s (± 0.34%) 4.51s (± 0.57%) +0.03s (+ 0.62%) 4.45s 4.59s
Emit Time 3.04s (± 0.39%) 3.04s (± 0.59%) -0.01s (- 0.20%) 3.00s 3.08s
Total Time 9.45s (± 0.25%) 9.48s (± 0.28%) +0.02s (+ 0.22%) 9.43s 9.53s
material-ui - node (v14.15.1, x64)
Memory used 471,526k (± 0.00%) 471,550k (± 0.00%) +24k (+ 0.01%) 471,525k 471,605k
Parse Time 2.05s (± 0.65%) 2.05s (± 0.46%) +0.00s (+ 0.20%) 2.03s 2.07s
Bind Time 0.70s (± 0.74%) 0.70s (± 0.00%) -0.00s (- 0.14%) 0.70s 0.70s
Check Time 12.58s (± 0.60%) 12.61s (± 0.60%) +0.04s (+ 0.28%) 12.49s 12.77s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.33s (± 0.53%) 15.37s (± 0.47%) +0.04s (+ 0.23%) 15.24s 15.51s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-198-generic
Architecturex64
Available Memory16 GB
Available Memory7 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 42751 10
Baseline master 10

1. Update the module.exports test to match the exports ones.
2. Add a test of evolving commonjs type.
3. Add a test of assignment as last statement.

(1) exposed a bug that required a better synthetic reference. (3)
exposed a bug that was most easily fixed by giving source files a
`endFlowNode` like functions and setting it in the binder.
@sandersn
Copy link
Member Author

@typescript-bot perf test this
@typescript-bot user test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 17, 2021

Heya @sandersn, I've started to run the perf test suite on this PR at 6880763. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 17, 2021

Heya @sandersn, I've started to run the parallelized community code test suite on this PR at 6880763. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..42751

Metric master 42751 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 345,850k (± 0.02%) 345,959k (± 0.02%) +110k (+ 0.03%) 345,816k 346,057k
Parse Time 1.92s (± 0.39%) 1.92s (± 0.52%) 0.00s ( 0.00%) 1.90s 1.94s
Bind Time 0.82s (± 0.45%) 0.82s (± 0.54%) -0.00s (- 0.36%) 0.81s 0.83s
Check Time 4.95s (± 0.36%) 5.05s (± 0.50%) +0.09s (+ 1.92%) 5.00s 5.11s
Emit Time 5.25s (± 0.64%) 5.26s (± 0.75%) +0.01s (+ 0.29%) 5.20s 5.38s
Total Time 12.94s (± 0.39%) 13.05s (± 0.44%) +0.11s (+ 0.87%) 12.96s 13.19s
Compiler-Unions - node (v10.16.3, x64)
Memory used 214,444k (± 0.06%) 214,438k (± 0.06%) -6k (- 0.00%) 214,001k 214,614k
Parse Time 0.78s (± 0.88%) 0.78s (± 0.61%) +0.00s (+ 0.13%) 0.77s 0.79s
Bind Time 0.49s (± 1.54%) 0.49s (± 1.43%) -0.00s (- 0.81%) 0.48s 0.51s
Check Time 10.65s (± 0.35%) 10.62s (± 0.39%) -0.03s (- 0.30%) 10.51s 10.73s
Emit Time 2.33s (± 1.40%) 2.32s (± 1.01%) -0.01s (- 0.34%) 2.26s 2.36s
Total Time 14.25s (± 0.45%) 14.21s (± 0.23%) -0.04s (- 0.31%) 14.13s 14.27s
Monaco - node (v10.16.3, x64)
Memory used 355,281k (± 0.03%) 355,297k (± 0.01%) +17k (+ 0.00%) 355,210k 355,364k
Parse Time 1.56s (± 0.72%) 1.54s (± 0.38%) -0.01s (- 0.71%) 1.53s 1.56s
Bind Time 0.72s (± 0.68%) 0.73s (± 0.82%) +0.00s (+ 0.28%) 0.71s 0.74s
Check Time 5.09s (± 0.34%) 5.14s (± 0.41%) +0.05s (+ 0.92%) 5.10s 5.19s
Emit Time 2.80s (± 0.59%) 2.79s (± 0.49%) -0.01s (- 0.43%) 2.76s 2.82s
Total Time 10.17s (± 0.28%) 10.19s (± 0.37%) +0.02s (+ 0.21%) 10.11s 10.29s
TFS - node (v10.16.3, x64)
Memory used 308,168k (± 0.01%) 308,137k (± 0.01%) -30k (- 0.01%) 308,066k 308,269k
Parse Time 1.20s (± 0.56%) 1.20s (± 0.43%) +0.00s (+ 0.33%) 1.19s 1.21s
Bind Time 0.68s (± 0.44%) 0.69s (± 0.75%) +0.01s (+ 1.03%) 0.68s 0.70s
Check Time 4.57s (± 0.58%) 4.62s (± 0.68%) +0.05s (+ 1.18%) 4.57s 4.70s
Emit Time 2.92s (± 0.59%) 2.92s (± 0.59%) +0.00s (+ 0.10%) 2.89s 2.98s
Total Time 9.36s (± 0.40%) 9.43s (± 0.51%) +0.07s (+ 0.70%) 9.35s 9.52s
material-ui - node (v10.16.3, x64)
Memory used 495,552k (± 0.02%) 495,766k (± 0.02%) +214k (+ 0.04%) 495,539k 495,988k
Parse Time 1.98s (± 0.70%) 1.97s (± 0.28%) -0.01s (- 0.35%) 1.95s 1.98s
Bind Time 0.65s (± 0.68%) 0.65s (± 0.62%) -0.00s (- 0.46%) 0.64s 0.66s
Check Time 13.93s (± 0.40%) 13.98s (± 0.52%) +0.05s (+ 0.39%) 13.85s 14.14s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.56s (± 0.38%) 16.60s (± 0.42%) +0.04s (+ 0.25%) 16.47s 16.75s
Angular - node (v12.1.0, x64)
Memory used 323,455k (± 0.03%) 323,300k (± 0.09%) -155k (- 0.05%) 322,146k 323,500k
Parse Time 1.90s (± 0.58%) 1.91s (± 0.61%) +0.01s (+ 0.32%) 1.89s 1.94s
Bind Time 0.80s (± 0.62%) 0.80s (± 1.02%) +0.00s (+ 0.50%) 0.79s 0.83s
Check Time 4.84s (± 0.65%) 4.94s (± 0.60%) +0.10s (+ 2.00%) 4.88s 5.01s
Emit Time 5.41s (± 0.46%) 5.43s (± 0.57%) +0.02s (+ 0.39%) 5.37s 5.51s
Total Time 12.94s (± 0.33%) 13.07s (± 0.34%) +0.13s (+ 0.99%) 13.00s 13.20s
Compiler-Unions - node (v12.1.0, x64)
Memory used 199,776k (± 0.11%) 199,764k (± 0.06%) -12k (- 0.01%) 199,509k 199,983k
Parse Time 0.76s (± 0.92%) 0.76s (± 0.65%) +0.00s (+ 0.53%) 0.75s 0.77s
Bind Time 0.50s (± 0.80%) 0.50s (± 0.73%) -0.00s (- 0.60%) 0.49s 0.50s
Check Time 9.66s (± 0.63%) 9.71s (± 0.79%) +0.05s (+ 0.51%) 9.60s 9.93s
Emit Time 2.37s (± 1.31%) 2.35s (± 1.71%) -0.01s (- 0.42%) 2.29s 2.47s
Total Time 13.29s (± 0.61%) 13.33s (± 0.61%) +0.04s (+ 0.31%) 13.19s 13.53s
Monaco - node (v12.1.0, x64)
Memory used 337,504k (± 0.02%) 337,474k (± 0.05%) -30k (- 0.01%) 336,893k 337,675k
Parse Time 1.53s (± 0.58%) 1.53s (± 0.49%) +0.01s (+ 0.46%) 1.52s 1.55s
Bind Time 0.70s (± 0.63%) 0.70s (± 0.68%) +0.00s (+ 0.14%) 0.70s 0.72s
Check Time 4.92s (± 0.64%) 4.97s (± 0.57%) +0.06s (+ 1.14%) 4.91s 5.06s
Emit Time 2.84s (± 0.45%) 2.87s (± 1.08%) +0.03s (+ 0.95%) 2.80s 2.94s
Total Time 9.98s (± 0.34%) 10.07s (± 0.59%) +0.09s (+ 0.91%) 9.98s 10.25s
TFS - node (v12.1.0, x64)
Memory used 292,377k (± 0.03%) 292,404k (± 0.02%) +27k (+ 0.01%) 292,286k 292,544k
Parse Time 1.23s (± 0.73%) 1.22s (± 0.67%) -0.00s (- 0.41%) 1.20s 1.24s
Bind Time 0.66s (± 1.71%) 0.65s (± 0.80%) -0.01s (- 1.21%) 0.64s 0.66s
Check Time 4.50s (± 0.66%) 4.54s (± 0.41%) +0.04s (+ 0.93%) 4.51s 4.59s
Emit Time 2.94s (± 1.09%) 2.95s (± 1.13%) +0.01s (+ 0.31%) 2.88s 3.04s
Total Time 9.32s (± 0.48%) 9.36s (± 0.54%) +0.04s (+ 0.40%) 9.25s 9.47s
material-ui - node (v12.1.0, x64)
Memory used 472,733k (± 0.01%) 472,800k (± 0.06%) +67k (+ 0.01%) 471,672k 473,061k
Parse Time 1.99s (± 0.65%) 1.99s (± 0.46%) -0.00s (- 0.20%) 1.97s 2.01s
Bind Time 0.64s (± 0.69%) 0.64s (± 0.70%) -0.00s (- 0.62%) 0.63s 0.65s
Check Time 12.47s (± 0.63%) 12.55s (± 0.82%) +0.08s (+ 0.61%) 12.37s 12.79s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.10s (± 0.60%) 15.18s (± 0.69%) +0.07s (+ 0.48%) 14.99s 15.40s
Angular - node (v14.15.1, x64)
Memory used 322,049k (± 0.01%) 322,064k (± 0.01%) +15k (+ 0.00%) 322,002k 322,117k
Parse Time 1.91s (± 0.39%) 1.92s (± 0.70%) +0.01s (+ 0.31%) 1.89s 1.95s
Bind Time 0.85s (± 0.87%) 0.86s (± 0.77%) +0.01s (+ 1.18%) 0.85s 0.88s
Check Time 4.85s (± 0.29%) 4.92s (± 0.20%) +0.07s (+ 1.42%) 4.91s 4.95s
Emit Time 5.45s (± 0.52%) 5.47s (± 0.72%) +0.02s (+ 0.35%) 5.39s 5.57s
Total Time 13.06s (± 0.29%) 13.17s (± 0.43%) +0.11s (+ 0.82%) 13.06s 13.30s
Compiler-Unions - node (v14.15.1, x64)
Memory used 200,755k (± 0.56%) 201,189k (± 0.63%) +434k (+ 0.22%) 199,055k 202,925k
Parse Time 0.80s (± 0.75%) 0.80s (± 0.37%) +0.00s (+ 0.25%) 0.79s 0.80s
Bind Time 0.53s (± 0.89%) 0.53s (± 0.65%) -0.01s (- 1.13%) 0.52s 0.53s
Check Time 9.69s (± 0.61%) 9.66s (± 0.35%) -0.03s (- 0.36%) 9.59s 9.73s
Emit Time 2.38s (± 1.07%) 2.33s (± 0.97%) -0.04s (- 1.81%) 2.30s 2.41s
Total Time 13.39s (± 0.51%) 13.31s (± 0.32%) -0.08s (- 0.59%) 13.22s 13.39s
Monaco - node (v14.15.1, x64)
Memory used 336,857k (± 0.01%) 336,887k (± 0.01%) +30k (+ 0.01%) 336,835k 336,967k
Parse Time 1.56s (± 0.69%) 1.55s (± 0.42%) -0.01s (- 0.58%) 1.54s 1.56s
Bind Time 0.73s (± 0.79%) 0.73s (± 0.65%) +0.00s (+ 0.41%) 0.73s 0.75s
Check Time 4.84s (± 0.38%) 4.90s (± 0.58%) +0.06s (+ 1.16%) 4.85s 4.99s
Emit Time 2.90s (± 0.40%) 2.93s (± 0.60%) +0.03s (+ 1.03%) 2.90s 2.99s
Total Time 10.03s (± 0.21%) 10.11s (± 0.41%) +0.07s (+ 0.73%) 10.05s 10.25s
TFS - node (v14.15.1, x64)
Memory used 291,529k (± 0.01%) 291,580k (± 0.01%) +51k (+ 0.02%) 291,548k 291,617k
Parse Time 1.26s (± 1.06%) 1.24s (± 0.97%) -0.02s (- 1.27%) 1.22s 1.27s
Bind Time 0.69s (± 0.43%) 0.69s (± 0.48%) -0.00s (- 0.29%) 0.68s 0.70s
Check Time 4.50s (± 0.39%) 4.53s (± 0.44%) +0.03s (+ 0.60%) 4.48s 4.57s
Emit Time 3.06s (± 0.84%) 3.04s (± 0.53%) -0.02s (- 0.59%) 3.01s 3.09s
Total Time 9.50s (± 0.39%) 9.50s (± 0.25%) -0.01s (- 0.07%) 9.45s 9.54s
material-ui - node (v14.15.1, x64)
Memory used 471,501k (± 0.01%) 471,593k (± 0.00%) +92k (+ 0.02%) 471,556k 471,619k
Parse Time 2.04s (± 0.59%) 2.06s (± 0.78%) +0.02s (+ 0.83%) 2.02s 2.10s
Bind Time 0.70s (± 0.32%) 0.70s (± 0.79%) +0.00s (+ 0.43%) 0.69s 0.71s
Check Time 12.62s (± 0.42%) 12.64s (± 0.50%) +0.02s (+ 0.13%) 12.51s 12.77s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.36s (± 0.35%) 15.40s (± 0.38%) +0.04s (+ 0.26%) 15.27s 15.53s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-198-generic
Architecturex64
Available Memory16 GB
Available Memory7 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 42751 10
Baseline master 10

@sandersn
Copy link
Member Author

Perf run: There's a lot of variance in the node 14 results, but it's both positive and negative. I don't think there's any real impact here.
User tests:

  • async uses the undefined>>assignment pattern and removes 205 errors, one for each export
  • debug uses feature detection and conditional assignment of an export in one place. It doesn't change the type, so technically just the "drop errors" part of this PR is needed.
  • npm: nervous laugh mutation of exports to indicate initialisation! npm is best code base~~~

@sandersn sandersn merged commit dd1ef88 into master Apr 7, 2021
@sandersn sandersn deleted the allow-redeclaring-commonjs-aliases-with-initial-undefined branch April 7, 2021 00:07
sandersn added a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Apr 8, 2021
(New changes to Typescript)[microsoft/TypeScript#42751]
make it better at figuring out the type of
`module.exports`. Unfortunately, it still gets confused by some bundler
outputs, which is what the npm-naming rule uses to compare index.d.ts to
find out if the types match the original JS well enough.

This PR adds exemptions to the 7 packages that started failing after the
linked Typescript PR was merged.
sandersn added a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Apr 8, 2021
(New changes to Typescript)[microsoft/TypeScript#42751]
make it better at figuring out the type of
`module.exports`. Unfortunately, it still gets confused by some bundler
outputs, which is what the npm-naming rule uses to compare index.d.ts to
find out if the types match the original JS well enough.

This PR adds exemptions to the 7 packages that started failing after the
linked Typescript PR was merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Commonjs exports should allow duplicates in some cases
3 participants