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

Avoid calculating union in spread if property types are identical #53413

Merged
merged 2 commits into from
Mar 21, 2023

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Mar 21, 2023

For #52345

When spreading, we remove undefined from the right type and union it with the left. If the two types are huge but overlap, we'll add all of the union's members together into one big list, then run subtype reduction over it, which for this test takes a long time. But, we can skip that work if we can recognize that left/right are the same. With #53406, this eliminates all of the bottlenecks in #52345.

Since this spread stuff is tricky, I generated a test which tests all combos of spreading + optional + missing to verify that I don't screw it up.

Likely, there's something more general that could be done to getUnionType here; it always recurses into every union and then does subtype reduction. I wonder if we can deduplicate the list first (ignoring undefined-ness), and trivially bail out early where possible, but that seemed a little tricky.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Mar 21, 2023
@jakebailey jakebailey changed the title Avoid calculating union in spread if types are identical Avoid calculating union in spread if property types are identical Mar 21, 2023
@jakebailey
Copy link
Member Author

@typescript-bot test this
@typescript-bot test top100
@typescript-bot user test this
@typescript-bot run dt
@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Heya @jakebailey, I've started to run the abridged perf test suite on this PR at 958017d. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Heya @jakebailey, I've started to run the diff-based user code test suite on this PR at 958017d. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Heya @jakebailey, I've started to run the diff-based top-repos suite on this PR at 958017d. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Heya @jakebailey, I've started to run the extended test suite on this PR at 958017d. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user test suite comparing main and refs/pull/53413/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..53413

Metric main 53413 Delta Best Worst p-value
Angular - node (v16.17.1, x64)
Memory used 361,392k (± 0.01%) 361,422k (± 0.01%) ~ 361,362k 361,465k p=0.199 n=6
Parse Time 3.54s (± 0.60%) 3.52s (± 0.91%) ~ 3.49s 3.56s p=0.466 n=6
Bind Time 1.18s (± 0.71%) 1.18s (± 0.46%) ~ 1.18s 1.19s p=0.855 n=6
Check Time 9.49s (± 0.44%) 9.54s (± 0.37%) ~ 9.50s 9.60s p=0.064 n=6
Emit Time 7.92s (± 0.37%) 7.97s (± 0.71%) ~ 7.92s 8.07s p=0.063 n=6
Total Time 22.13s (± 0.22%) 22.22s (± 0.30%) +0.10s (+ 0.44%) 22.13s 22.33s p=0.024 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 192,532k (± 0.03%) 192,515k (± 0.02%) ~ 192,463k 192,582k p=0.873 n=6
Parse Time 1.60s (± 0.85%) 1.59s (± 1.08%) ~ 1.56s 1.61s p=0.317 n=6
Bind Time 0.83s (± 0.62%) 0.82s (± 0.00%) -0.01s (- 0.81%) 0.82s 0.82s p=0.025 n=6
Check Time 10.18s (± 0.45%) 10.11s (± 0.67%) -0.07s (- 0.72%) 10.06s 10.24s p=0.043 n=6
Emit Time 2.99s (± 1.21%) 3.00s (± 1.02%) ~ 2.96s 3.04s p=0.809 n=6
Total Time 15.60s (± 0.30%) 15.52s (± 0.64%) ~ 15.43s 15.69s p=0.126 n=6
Monaco - node (v16.17.1, x64)
Memory used 345,562k (± 0.01%) 345,556k (± 0.01%) ~ 345,538k 345,582k p=0.378 n=6
Parse Time 2.73s (± 0.50%) 2.73s (± 0.51%) ~ 2.71s 2.74s p=0.935 n=6
Bind Time 1.09s (± 0.47%) 1.09s (± 0.47%) ~ 1.08s 1.09s p=1.000 n=6
Check Time 7.76s (± 0.52%) 7.75s (± 0.57%) ~ 7.68s 7.81s p=0.808 n=6
Emit Time 4.48s (± 0.58%) 4.46s (± 1.05%) ~ 4.43s 4.55s p=0.290 n=6
Total Time 16.06s (± 0.35%) 16.02s (± 0.52%) ~ 15.93s 16.16s p=0.377 n=6
TFS - node (v16.17.1, x64)
Memory used 299,778k (± 0.01%) 299,816k (± 0.01%) ~ 299,754k 299,863k p=0.173 n=6
Parse Time 2.17s (± 0.86%) 2.16s (± 0.48%) ~ 2.14s 2.17s p=0.102 n=6
Bind Time 1.23s (± 1.03%) 1.24s (± 1.14%) ~ 1.22s 1.26s p=0.249 n=6
Check Time 7.20s (± 0.39%) 7.17s (± 0.44%) ~ 7.12s 7.20s p=0.107 n=6
Emit Time 4.34s (± 0.50%) 4.33s (± 0.60%) ~ 4.30s 4.37s p=0.331 n=6
Total Time 14.93s (± 0.32%) 14.89s (± 0.28%) ~ 14.84s 14.96s p=0.173 n=6
material-ui - node (v16.17.1, x64)
Memory used 476,489k (± 0.02%) 476,371k (± 0.00%) -118k (- 0.02%) 476,351k 476,391k p=0.013 n=6
Parse Time 3.22s (± 1.21%) 3.22s (± 0.32%) ~ 3.20s 3.23s p=0.366 n=6
Bind Time 0.98s (± 3.78%) 0.95s (± 0.57%) -0.03s (- 2.72%) 0.95s 0.96s p=0.038 n=6
Check Time 18.00s (± 1.06%) 17.93s (± 0.40%) ~ 17.84s 18.03s p=0.688 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.20s (± 1.03%) 22.10s (± 0.31%) ~ 22.02s 22.18s p=0.689 n=6
xstate - node (v16.17.1, x64)
Memory used 550,558k (± 0.01%) 550,529k (± 0.01%) ~ 550,489k 550,600k p=0.471 n=6
Parse Time 3.95s (± 0.34%) 3.95s (± 0.23%) ~ 3.94s 3.96s p=0.681 n=6
Bind Time 1.79s (± 0.47%) 1.79s (± 0.58%) ~ 1.78s 1.81s p=1.000 n=6
Check Time 2.99s (± 0.47%) 2.99s (± 0.91%) ~ 2.96s 3.02s p=0.513 n=6
Emit Time 0.09s (± 0.00%) 0.09s (± 0.00%) ~ 0.09s 0.09s p=1.000 n=6
Total Time 8.83s (± 0.34%) 8.83s (± 0.37%) ~ 8.79s 8.87s p=0.747 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v16.17.1, x64)
Scenarios
  • Angular - node (v16.17.1, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Monaco - node (v16.17.1, x64)
  • TFS - node (v16.17.1, x64)
  • material-ui - node (v16.17.1, x64)
  • xstate - node (v16.17.1, x64)
Benchmark Name Iterations
Current 53413 6
Baseline main 6

Developer Information:

Download Benchmark

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

We could probably build a similar check into getUnionType directly, but the undefined handling (as done here) does make it a bit tricker.

@typescript-bot typescript-bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Mar 21, 2023
@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top-repos suite comparing main and refs/pull/53413/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, it looks like the DT test run failed. Please check the log for more details.
You can check the log here.

@jakebailey
Copy link
Member Author

@typescript-bot run dt but this time don't fail please

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

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

Update: The results are in!

@jakebailey
Copy link
Member Author

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Heya @jakebailey, I've started to run the tarball bundle task on this PR at 958017d. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2023

Hey @jakebailey, 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/150524/artifacts?artifactName=tgz&fileId=500A00E3BCD5C97B02ABAC8526FB418BC7F239F8EF69AF70BD2D56952FEE16B702&fileName=/typescript-5.1.0-insiders.20230321.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/pr-build@5.1.0-pr-53413-14".;

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@jakebailey jakebailey merged commit 01de788 into microsoft:main Mar 21, 2023
@jakebailey jakebailey deleted the fix-52345-4 branch March 21, 2023 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants