Skip to content
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

When an intersection is going to produce an expression too complex error... #42772

Conversation

weswigham
Copy link
Member

eagerly perform reductions in a last-ditch effort to avoid the error. I've wanted to do something like this since #29949 was opened, and since we added getReducedType and associated machinery, alongside machinery for bailing when expressions are producing unions/intersections are too complex. I feel like we now have a scenario where it's justifiable to invoke the reduction machinery earlier than we normally do in order to try to save us from resorting to an "Expression produces a union type that is too complex to represent" error, since that error is ultimately heuristic and, in fact, the union produced is not too complex if significant reductions take place.

#29949 has had acceptable perf for awhile, it just also had a complexity error in it, so could already be considered "fixed". This really fixes #29949, IMO, by finally removing that "expression too complex" error once react's types are adjusted to make the two ref object types mutually exclusive by adding a current?: undefined property to the RefCallback type and the callback in ForwardedRef.

This shouldn't impact perf generally, since this fallback heuristic only takes effect when we would already issue an error.

…ror, eagerly perform reductions in a last-ditch effort to avoid the error
@weswigham
Copy link
Member Author

@typescript-bot perf test this
@typescript-bot run dt
@typescript-bot test this
@typescript-bot user test this
@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2021

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2021

Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at 757bee7. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2021

Heya @weswigham, I've started to run the extended test suite on this PR at 757bee7. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2021

Heya @weswigham, I've started to run the tarball bundle task on this PR at 757bee7. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2021

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

Update: The results are in!

// This is relevant for, eg, when looking at `(HTMLElement | null) & (SVGElement | null) & ... & undefined` where _usually_
// we'd allow for tons of garbage intermediate types like `null & SVGElement` to exist; but nobody ever really actually _wants_
// that, IMO. Those types can still exist in the type system; just... not when working with unions and intersections with massive
// cross-product growth potential.
Copy link
Member Author

@weswigham weswigham Feb 12, 2021

Choose a reason for hiding this comment

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

RE: This comment and associated logic. If we did this in all scenarios, it would be a breaking change; however since we only do it when we would have previously issued a Expression produces a union type that is too complex to represent error, it is not. I think we've had a desire to try to eliminate structurally branded primitives from the type system for awhile, and I think this is just one small corner where we can actually remove them and be pretty safe, without worrying about either breaking people or needing to provide an alternative.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2021

Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/95725/artifacts?artifactName=tgz&fileId=CB182C2B07B9E286D1BCF7271265890E5A97D579D9EB4FE73B5781A33AAE5D0F02&fileName=/typescript-4.3.0-insiders.20210212.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..42772

Metric master 42772 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 345,704k (± 0.03%) 345,630k (± 0.02%) -74k (- 0.02%) 345,466k 345,733k
Parse Time 1.91s (± 0.47%) 1.91s (± 0.47%) -0.01s (- 0.26%) 1.90s 1.93s
Bind Time 0.82s (± 0.70%) 0.82s (± 0.73%) +0.00s (+ 0.61%) 0.82s 0.84s
Check Time 4.96s (± 0.59%) 4.94s (± 0.40%) -0.02s (- 0.36%) 4.88s 4.97s
Emit Time 5.26s (± 0.62%) 5.27s (± 0.68%) +0.01s (+ 0.15%) 5.22s 5.35s
Total Time 12.95s (± 0.49%) 12.94s (± 0.35%) -0.01s (- 0.07%) 12.83s 13.02s
Compiler-Unions - node (v10.16.3, x64)
Memory used 214,483k (± 0.04%) 214,453k (± 0.04%) -30k (- 0.01%) 214,287k 214,651k
Parse Time 0.77s (± 0.67%) 0.78s (± 0.57%) +0.01s (+ 0.91%) 0.77s 0.79s
Bind Time 0.50s (± 0.66%) 0.50s (± 1.23%) +0.00s (+ 0.20%) 0.49s 0.51s
Check Time 10.60s (± 0.56%) 10.59s (± 0.60%) -0.01s (- 0.12%) 10.48s 10.75s
Emit Time 2.34s (± 0.92%) 2.33s (± 0.96%) -0.00s (- 0.13%) 2.28s 2.40s
Total Time 14.21s (± 0.43%) 14.20s (± 0.56%) -0.01s (- 0.08%) 14.08s 14.39s
Monaco - node (v10.16.3, x64)
Memory used 355,335k (± 0.02%) 355,286k (± 0.02%) -49k (- 0.01%) 355,102k 355,538k
Parse Time 1.55s (± 0.31%) 1.55s (± 0.52%) +0.00s (+ 0.19%) 1.53s 1.56s
Bind Time 0.72s (± 0.90%) 0.72s (± 1.22%) -0.00s (- 0.28%) 0.71s 0.75s
Check Time 5.10s (± 0.58%) 5.12s (± 0.58%) +0.01s (+ 0.29%) 5.08s 5.19s
Emit Time 2.80s (± 0.46%) 2.80s (± 1.08%) 0.00s ( 0.00%) 2.76s 2.90s
Total Time 10.17s (± 0.29%) 10.19s (± 0.58%) +0.02s (+ 0.18%) 10.10s 10.33s
TFS - node (v10.16.3, x64)
Memory used 308,123k (± 0.02%) 308,137k (± 0.03%) +14k (+ 0.00%) 307,964k 308,364k
Parse Time 1.20s (± 0.41%) 1.21s (± 0.62%) +0.00s (+ 0.17%) 1.19s 1.23s
Bind Time 0.68s (± 0.81%) 0.69s (± 0.87%) +0.00s (+ 0.59%) 0.67s 0.70s
Check Time 4.58s (± 0.59%) 4.60s (± 0.44%) +0.03s (+ 0.57%) 4.56s 4.66s
Emit Time 2.91s (± 1.06%) 2.93s (± 1.70%) +0.02s (+ 0.55%) 2.86s 3.08s
Total Time 9.38s (± 0.32%) 9.43s (± 0.65%) +0.05s (+ 0.50%) 9.32s 9.60s
material-ui - node (v10.16.3, x64)
Memory used 495,603k (± 0.01%) 495,665k (± 0.02%) +62k (+ 0.01%) 495,437k 495,780k
Parse Time 1.98s (± 0.65%) 1.98s (± 0.85%) +0.00s (+ 0.10%) 1.95s 2.02s
Bind Time 0.65s (± 0.61%) 0.65s (± 0.46%) +0.00s (+ 0.15%) 0.65s 0.66s
Check Time 13.89s (± 0.78%) 13.90s (± 0.40%) +0.02s (+ 0.11%) 13.76s 14.03s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.52s (± 0.72%) 16.54s (± 0.35%) +0.02s (+ 0.11%) 16.39s 16.63s
Angular - node (v12.1.0, x64)
Memory used 323,144k (± 0.10%) 323,261k (± 0.02%) +116k (+ 0.04%) 323,140k 323,511k
Parse Time 1.89s (± 0.66%) 1.90s (± 0.68%) +0.00s (+ 0.16%) 1.87s 1.92s
Bind Time 0.80s (± 1.04%) 0.80s (± 0.77%) +0.00s (+ 0.38%) 0.78s 0.81s
Check Time 4.87s (± 0.70%) 4.85s (± 0.38%) -0.03s (- 0.55%) 4.80s 4.88s
Emit Time 5.38s (± 0.51%) 5.41s (± 1.09%) +0.03s (+ 0.61%) 5.32s 5.56s
Total Time 12.94s (± 0.46%) 12.96s (± 0.52%) +0.01s (+ 0.08%) 12.84s 13.15s
Compiler-Unions - node (v12.1.0, x64)
Memory used 199,801k (± 0.10%) 199,849k (± 0.07%) +48k (+ 0.02%) 199,618k 200,138k
Parse Time 0.76s (± 0.64%) 0.76s (± 0.76%) -0.00s (- 0.13%) 0.75s 0.77s
Bind Time 0.50s (± 0.73%) 0.50s (± 1.04%) +0.00s (+ 0.60%) 0.49s 0.51s
Check Time 9.63s (± 0.27%) 9.66s (± 0.82%) +0.03s (+ 0.34%) 9.54s 9.86s
Emit Time 2.35s (± 1.17%) 2.37s (± 1.26%) +0.02s (+ 0.68%) 2.32s 2.46s
Total Time 13.24s (± 0.32%) 13.29s (± 0.71%) +0.05s (+ 0.35%) 13.10s 13.50s
Monaco - node (v12.1.0, x64)
Memory used 337,501k (± 0.02%) 337,508k (± 0.02%) +6k (+ 0.00%) 337,360k 337,658k
Parse Time 1.52s (± 1.12%) 1.54s (± 0.40%) +0.01s (+ 0.92%) 1.52s 1.55s
Bind Time 0.70s (± 0.80%) 0.70s (± 0.67%) +0.00s (+ 0.29%) 0.69s 0.71s
Check Time 4.89s (± 0.34%) 4.93s (± 0.70%) +0.04s (+ 0.76%) 4.86s 5.03s
Emit Time 2.84s (± 0.59%) 2.84s (± 0.83%) +0.01s (+ 0.18%) 2.79s 2.90s
Total Time 9.96s (± 0.27%) 10.01s (± 0.41%) +0.05s (+ 0.54%) 9.91s 10.10s
TFS - node (v12.1.0, x64)
Memory used 292,346k (± 0.02%) 292,324k (± 0.02%) -22k (- 0.01%) 292,206k 292,460k
Parse Time 1.22s (± 0.71%) 1.22s (± 0.69%) +0.00s (+ 0.25%) 1.21s 1.25s
Bind Time 0.66s (± 0.88%) 0.65s (± 0.89%) -0.00s (- 0.61%) 0.64s 0.66s
Check Time 4.48s (± 0.56%) 4.50s (± 0.53%) +0.02s (+ 0.33%) 4.43s 4.53s
Emit Time 2.93s (± 1.44%) 2.94s (± 1.13%) +0.01s (+ 0.31%) 2.84s 2.98s
Total Time 9.28s (± 0.63%) 9.31s (± 0.59%) +0.03s (+ 0.32%) 9.13s 9.40s
material-ui - node (v12.1.0, x64)
Memory used 472,552k (± 0.07%) 472,689k (± 0.05%) +137k (+ 0.03%) 471,702k 472,948k
Parse Time 1.99s (± 0.55%) 2.00s (± 0.45%) +0.00s (+ 0.20%) 1.98s 2.01s
Bind Time 0.64s (± 0.57%) 0.64s (± 0.81%) +0.00s (+ 0.79%) 0.63s 0.65s
Check Time 12.46s (± 0.76%) 12.56s (± 1.22%) +0.11s (+ 0.85%) 12.39s 13.12s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.09s (± 0.62%) 15.20s (± 1.01%) +0.12s (+ 0.77%) 15.02s 15.76s
Angular - node (v14.15.1, x64)
Memory used 321,819k (± 0.01%) 321,632k (± 0.10%) -188k (- 0.06%) 320,717k 321,904k
Parse Time 1.89s (± 0.36%) 1.90s (± 0.72%) +0.01s (+ 0.58%) 1.88s 1.94s
Bind Time 0.85s (± 0.70%) 0.84s (± 0.77%) -0.00s (- 0.47%) 0.83s 0.86s
Check Time 4.84s (± 0.48%) 4.85s (± 1.01%) +0.02s (+ 0.37%) 4.79s 5.00s
Emit Time 5.46s (± 0.35%) 5.49s (± 0.74%) +0.04s (+ 0.66%) 5.43s 5.60s
Total Time 13.03s (± 0.29%) 13.10s (± 0.70%) +0.06s (+ 0.49%) 12.96s 13.34s
Compiler-Unions - node (v14.15.1, x64)
Memory used 200,560k (± 0.57%) 200,073k (± 0.48%) -488k (- 0.24%) 199,060k 202,859k
Parse Time 0.80s (± 0.62%) 0.80s (± 0.81%) +0.00s (+ 0.25%) 0.79s 0.82s
Bind Time 0.53s (± 0.95%) 0.53s (± 0.65%) +0.00s (+ 0.38%) 0.52s 0.53s
Check Time 9.71s (± 1.27%) 9.69s (± 0.27%) -0.02s (- 0.19%) 9.61s 9.73s
Emit Time 2.35s (± 1.23%) 2.36s (± 1.57%) +0.02s (+ 0.64%) 2.30s 2.47s
Total Time 13.38s (± 0.99%) 13.38s (± 0.30%) +0.00s (+ 0.01%) 13.29s 13.49s
Monaco - node (v14.15.1, x64)
Memory used 336,851k (± 0.01%) 336,866k (± 0.01%) +15k (+ 0.00%) 336,804k 336,959k
Parse Time 1.55s (± 0.57%) 1.56s (± 0.78%) +0.01s (+ 0.32%) 1.54s 1.58s
Bind Time 0.73s (± 0.99%) 0.73s (± 0.64%) -0.00s (- 0.27%) 0.72s 0.74s
Check Time 4.83s (± 0.50%) 4.84s (± 0.48%) +0.01s (+ 0.31%) 4.79s 4.89s
Emit Time 2.91s (± 0.28%) 2.92s (± 0.41%) +0.00s (+ 0.17%) 2.89s 2.94s
Total Time 10.02s (± 0.33%) 10.05s (± 0.29%) +0.02s (+ 0.24%) 9.98s 10.10s
TFS - node (v14.15.1, x64)
Memory used 291,534k (± 0.01%) 291,542k (± 0.00%) +8k (+ 0.00%) 291,506k 291,568k
Parse Time 1.24s (± 0.89%) 1.24s (± 0.94%) -0.00s (- 0.16%) 1.22s 1.27s
Bind Time 0.69s (± 0.58%) 0.69s (± 0.68%) +0.00s (+ 0.15%) 0.68s 0.70s
Check Time 4.51s (± 0.33%) 4.47s (± 0.25%) -0.04s (- 0.84%) 4.45s 4.49s
Emit Time 3.04s (± 0.86%) 3.03s (± 0.45%) -0.00s (- 0.16%) 3.01s 3.06s
Total Time 9.48s (± 0.38%) 9.44s (± 0.23%) -0.04s (- 0.43%) 9.38s 9.48s
material-ui - node (v14.15.1, x64)
Memory used 471,289k (± 0.08%) 471,519k (± 0.01%) +229k (+ 0.05%) 471,452k 471,567k
Parse Time 2.04s (± 0.67%) 2.06s (± 0.55%) +0.02s (+ 0.73%) 2.03s 2.08s
Bind Time 0.70s (± 0.52%) 0.70s (± 0.68%) +0.00s (+ 0.14%) 0.69s 0.71s
Check Time 12.64s (± 1.01%) 12.57s (± 0.48%) -0.07s (- 0.52%) 12.50s 12.77s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.38s (± 0.79%) 15.33s (± 0.40%) -0.05s (- 0.35%) 15.23s 15.52s
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 42772 10
Baseline master 10

@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.

@sandersn
Copy link
Member

Unfortunately, we never finished reviewing this PR. It is pretty old now, so I'm going to close it to reduce the number of open PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

tsc, tsserver: hangs with large union type and object spread in React HOC (strict mode)
3 participants