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

Add Dependent-Type-Like Functions [Experiment] #33237

Closed

Conversation

rubenpieters
Copy link

@rubenpieters rubenpieters commented Sep 4, 2019

Initial experiments for implementing dependent-type-like functions, #33014 .

  • Step 1: check performance impact for binding return statements.

@jack-williams
Copy link
Collaborator

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 4, 2019

Heya @jack-williams, I've started to run the perf test suite on this PR at 2f44452. You can monitor the build here. It should now contribute to this PR's status checks.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@jack-williams
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..33237

Metric master 33237 Delta Best Worst
Angular - node (v12.1.0, x64)
Memory used 325,509k (± 0.02%) 325,862k (± 0.05%) +353k (+ 0.11%) 325,286k 326,143k
Parse Time 1.48s (± 0.52%) 1.49s (± 0.72%) +0.01s (+ 0.54%) 1.46s 1.51s
Bind Time 0.76s (± 1.02%) 0.77s (± 0.76%) +0.01s (+ 0.79%) 0.75s 0.78s
Check Time 4.18s (± 0.61%) 4.21s (± 0.46%) +0.03s (+ 0.74%) 4.15s 4.24s
Emit Time 5.25s (± 0.94%) 5.26s (± 0.71%) +0.00s (+ 0.06%) 5.19s 5.35s
Total Time 11.67s (± 0.53%) 11.72s (± 0.45%) +0.05s (+ 0.44%) 11.59s 11.83s
Monaco - node (v12.1.0, x64)
Memory used 345,904k (± 0.02%) 346,014k (± 0.01%) +110k (+ 0.03%) 345,878k 346,099k
Parse Time 1.23s (± 0.77%) 1.22s (± 0.71%) -0.00s (- 0.41%) 1.20s 1.24s
Bind Time 0.67s (± 0.83%) 0.68s (± 0.95%) +0.01s (+ 0.89%) 0.66s 0.69s
Check Time 4.27s (± 0.71%) 4.25s (± 0.37%) -0.01s (- 0.35%) 4.21s 4.28s
Emit Time 2.88s (± 1.13%) 2.86s (± 0.71%) -0.02s (- 0.56%) 2.81s 2.90s
Total Time 9.04s (± 0.57%) 9.01s (± 0.39%) -0.03s (- 0.33%) 8.93s 9.08s
TFS - node (v12.1.0, x64)
Memory used 301,355k (± 0.02%) 301,502k (± 0.02%) +147k (+ 0.05%) 301,361k 301,605k
Parse Time 0.95s (± 0.74%) 0.95s (± 0.99%) +0.00s (+ 0.42%) 0.93s 0.98s
Bind Time 0.63s (± 1.85%) 0.62s (± 0.95%) -0.00s (- 0.32%) 0.61s 0.64s
Check Time 3.85s (± 0.50%) 3.86s (± 0.51%) +0.01s (+ 0.21%) 3.83s 3.91s
Emit Time 2.94s (± 0.54%) 2.96s (± 0.64%) +0.03s (+ 0.85%) 2.92s 3.02s
Total Time 8.37s (± 0.41%) 8.40s (± 0.40%) +0.03s (+ 0.39%) 8.35s 8.49s
Angular - node (v8.9.0, x64)
Memory used 344,214k (± 0.02%) 344,588k (± 0.02%) +374k (+ 0.11%) 344,432k 344,718k
Parse Time 1.98s (± 0.44%) 1.99s (± 0.64%) +0.01s (+ 0.45%) 1.98s 2.04s
Bind Time 0.82s (± 0.73%) 0.82s (± 0.82%) +0.00s (+ 0.25%) 0.81s 0.84s
Check Time 5.04s (± 0.74%) 5.03s (± 0.77%) -0.02s (- 0.32%) 4.95s 5.12s
Emit Time 6.11s (± 0.69%) 6.08s (± 0.62%) -0.03s (- 0.43%) 6.00s 6.18s
Total Time 13.94s (± 0.25%) 13.91s (± 0.46%) -0.03s (- 0.24%) 13.78s 14.04s
Monaco - node (v8.9.0, x64)
Memory used 363,651k (± 0.01%) 363,778k (± 0.01%) +127k (+ 0.03%) 363,669k 363,879k
Parse Time 1.55s (± 0.36%) 1.56s (± 0.41%) +0.01s (+ 0.64%) 1.55s 1.58s
Bind Time 0.89s (± 0.56%) 0.89s (± 1.08%) +0.01s (+ 0.68%) 0.87s 0.92s
Check Time 5.12s (± 1.83%) 5.13s (± 1.48%) +0.01s (+ 0.14%) 5.00s 5.32s
Emit Time 3.17s (± 4.51%) 3.21s (± 4.11%) +0.05s (+ 1.45%) 2.94s 3.37s
Total Time 10.73s (± 0.57%) 10.80s (± 0.75%) +0.07s (+ 0.61%) 10.60s 10.98s
TFS - node (v8.9.0, x64)
Memory used 317,620k (± 0.01%) 317,793k (± 0.01%) +173k (+ 0.05%) 317,689k 317,853k
Parse Time 1.25s (± 0.38%) 1.26s (± 0.59%) +0.01s (+ 0.80%) 1.25s 1.28s
Bind Time 0.67s (± 0.74%) 0.68s (± 3.83%) +0.01s (+ 1.65%) 0.66s 0.78s
Check Time 4.47s (± 0.41%) 4.46s (± 0.85%) -0.01s (- 0.25%) 4.33s 4.52s
Emit Time 3.07s (± 0.53%) 3.06s (± 0.24%) -0.01s (- 0.39%) 3.04s 3.07s
Total Time 9.47s (± 0.31%) 9.46s (± 0.23%) -0.00s (- 0.02%) 9.42s 9.50s
Angular - node (v8.9.0, x86)
Memory used 194,966k (± 0.02%) 195,175k (± 0.02%) +209k (+ 0.11%) 195,105k 195,260k
Parse Time 1.93s (± 0.62%) 1.94s (± 0.69%) +0.02s (+ 0.88%) 1.92s 1.99s
Bind Time 0.95s (± 0.78%) 0.95s (± 0.55%) -0.00s (- 0.11%) 0.94s 0.96s
Check Time 4.60s (± 0.39%) 4.62s (± 0.41%) +0.03s (+ 0.54%) 4.58s 4.66s
Emit Time 5.80s (± 0.86%) 5.85s (± 0.85%) +0.05s (+ 0.86%) 5.71s 5.96s
Total Time 13.27s (± 0.49%) 13.37s (± 0.35%) +0.09s (+ 0.71%) 13.28s 13.47s
Monaco - node (v8.9.0, x86)
Memory used 203,212k (± 0.02%) 203,291k (± 0.01%) +79k (+ 0.04%) 203,237k 203,350k
Parse Time 1.61s (± 0.68%) 1.62s (± 0.85%) +0.01s (+ 0.50%) 1.60s 1.66s
Bind Time 0.72s (± 0.72%) 0.73s (± 0.83%) +0.01s (+ 0.83%) 0.71s 0.74s
Check Time 4.89s (± 0.52%) 4.90s (± 0.81%) +0.01s (+ 0.20%) 4.81s 5.00s
Emit Time 3.20s (± 1.07%) 3.20s (± 1.34%) -0.01s (- 0.25%) 3.14s 3.33s
Total Time 10.42s (± 0.52%) 10.44s (± 0.80%) +0.02s (+ 0.16%) 10.26s 10.66s
TFS - node (v8.9.0, x86)
Memory used 178,524k (± 0.01%) 178,582k (± 0.03%) +58k (+ 0.03%) 178,510k 178,735k
Parse Time 1.31s (± 0.90%) 1.31s (± 0.44%) +0.00s (+ 0.31%) 1.30s 1.33s
Bind Time 0.65s (± 1.43%) 0.64s (± 0.70%) -0.01s (- 1.54%) 0.63s 0.65s
Check Time 4.29s (± 0.60%) 4.29s (± 0.73%) -0.00s (- 0.09%) 4.24s 4.34s
Emit Time 2.88s (± 0.99%) 2.86s (± 0.79%) -0.01s (- 0.49%) 2.78s 2.89s
Total Time 9.13s (± 0.41%) 9.10s (± 0.37%) -0.02s (- 0.26%) 9.04s 9.19s
Angular - node (v9.0.0, x64)
Memory used 343,831k (± 0.01%) 344,215k (± 0.01%) +384k (+ 0.11%) 344,125k 344,351k
Parse Time 1.72s (± 0.46%) 1.72s (± 0.56%) -0.00s (- 0.06%) 1.69s 1.74s
Bind Time 0.76s (± 0.63%) 0.77s (± 0.64%) +0.01s (+ 1.19%) 0.76s 0.78s
Check Time 4.78s (± 0.59%) 4.76s (± 0.51%) -0.01s (- 0.25%) 4.70s 4.84s
Emit Time 5.60s (± 1.30%) 5.72s (± 1.86%) +0.12s (+ 2.14%) 5.47s 5.90s
Total Time 12.86s (± 0.66%) 12.97s (± 0.80%) +0.11s (+ 0.89%) 12.71s 13.12s
Monaco - node (v9.0.0, x64)
Memory used 363,407k (± 0.02%) 363,555k (± 0.02%) +148k (+ 0.04%) 363,427k 363,793k
Parse Time 1.32s (± 0.56%) 1.33s (± 0.56%) +0.01s (+ 0.76%) 1.32s 1.35s
Bind Time 0.84s (± 1.18%) 0.84s (± 1.08%) +0.00s (+ 0.36%) 0.82s 0.86s
Check Time 5.02s (± 1.81%) 5.03s (± 1.75%) +0.01s (+ 0.22%) 4.93s 5.20s
Emit Time 3.17s (± 5.21%) 3.20s (± 5.22%) +0.02s (+ 0.76%) 2.90s 3.41s
Total Time 10.36s (± 0.96%) 10.40s (± 0.90%) +0.04s (+ 0.42%) 10.24s 10.56s
TFS - node (v9.0.0, x64)
Memory used 317,410k (± 0.01%) 317,533k (± 0.01%) +122k (+ 0.04%) 317,455k 317,621k
Parse Time 1.04s (± 0.50%) 1.05s (± 0.57%) +0.01s (+ 0.58%) 1.03s 1.06s
Bind Time 0.62s (± 0.76%) 0.62s (± 0.93%) 0.00s ( 0.00%) 0.61s 0.63s
Check Time 4.36s (± 0.39%) 4.38s (± 0.72%) +0.02s (+ 0.41%) 4.33s 4.49s
Emit Time 3.19s (± 0.65%) 3.21s (± 0.98%) +0.02s (+ 0.56%) 3.15s 3.29s
Total Time 9.21s (± 0.26%) 9.25s (± 0.58%) +0.04s (+ 0.43%) 9.17s 9.44s
Angular - node (v9.0.0, x86)
Memory used 195,069k (± 0.03%) 195,264k (± 0.02%) +195k (+ 0.10%) 195,167k 195,352k
Parse Time 1.62s (± 0.36%) 1.64s (± 0.98%) +0.02s (+ 0.99%) 1.60s 1.68s
Bind Time 0.89s (± 0.53%) 0.89s (± 0.76%) +0.00s (+ 0.45%) 0.88s 0.91s
Check Time 4.24s (± 0.61%) 4.24s (± 0.43%) +0.01s (+ 0.12%) 4.20s 4.28s
Emit Time 5.53s (± 1.20%) 5.52s (± 0.77%) -0.00s (- 0.05%) 5.44s 5.62s
Total Time 12.27s (± 0.66%) 12.29s (± 0.47%) +0.02s (+ 0.17%) 12.16s 12.42s
Monaco - node (v9.0.0, x86)
Memory used 203,277k (± 0.02%) 203,351k (± 0.02%) +74k (+ 0.04%) 203,229k 203,475k
Parse Time 1.35s (± 0.74%) 1.35s (± 0.74%) +0.01s (+ 0.45%) 1.33s 1.37s
Bind Time 0.64s (± 0.69%) 0.65s (± 1.06%) +0.00s (+ 0.47%) 0.63s 0.66s
Check Time 4.71s (± 0.53%) 4.72s (± 0.58%) +0.01s (+ 0.15%) 4.65s 4.77s
Emit Time 3.10s (± 0.47%) 3.11s (± 0.72%) +0.01s (+ 0.29%) 3.06s 3.17s
Total Time 9.80s (± 0.37%) 9.83s (± 0.44%) +0.03s (+ 0.27%) 9.70s 9.91s
TFS - node (v9.0.0, x86)
Memory used 178,553k (± 0.03%) 178,647k (± 0.01%) +94k (+ 0.05%) 178,587k 178,687k
Parse Time 1.06s (± 0.54%) 1.06s (± 0.45%) +0.00s (+ 0.28%) 1.06s 1.08s
Bind Time 0.58s (± 0.63%) 0.58s (± 1.16%) +0.00s (+ 0.17%) 0.57s 0.59s
Check Time 4.15s (± 0.65%) 4.16s (± 0.70%) +0.01s (+ 0.19%) 4.09s 4.22s
Emit Time 2.78s (± 0.96%) 2.78s (± 0.92%) +0.01s (+ 0.18%) 2.69s 2.82s
Total Time 8.57s (± 0.41%) 8.57s (± 0.53%) +0.01s (+ 0.06%) 8.43s 8.63s
System
Machine Namets-ci-ubuntu.redmond.corp.microsoft.com
Platformlinux 4.4.0-142-generic
Architecturex64
Available Memory16 GB
Available Memory1 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v12.1.0, x64)
  • node (v8.9.0, x64)
  • node (v8.9.0, x86)
  • node (v9.0.0, x64)
  • node (v9.0.0, x86)
Scenarios
  • Angular - node (v12.1.0, x64)
  • Angular - node (v8.9.0, x64)
  • Angular - node (v8.9.0, x86)
  • Angular - node (v9.0.0, x64)
  • Angular - node (v9.0.0, x86)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v8.9.0, x64)
  • Monaco - node (v8.9.0, x86)
  • Monaco - node (v9.0.0, x64)
  • Monaco - node (v9.0.0, x86)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v8.9.0, x64)
  • TFS - node (v8.9.0, x86)
  • TFS - node (v9.0.0, x64)
  • TFS - node (v9.0.0, x86)
Benchmark Name Iterations
Current 33237 10
Baseline master 10

@jack-williams jack-williams added the Experiment A fork with an experimental idea which might not make it into master label Sep 4, 2019
@msftclas
Copy link

msftclas commented Nov 25, 2019

CLA assistant check
All CLA requirements met.

@rubenpieters
Copy link
Author

rubenpieters commented Nov 25, 2019

I have pushed an initial implementation of this feature based on input from @jack-williams .

Roughly it works as follows: A getTypeMapper function is passed around in the typechecker functions, to activate the feature the createConstructTypeMapper function is passed (currently only in checkReturnStatement). This function returns a cached version of the type mapper, or creates it if it doesn't exist.

This type mapper creates an instantiation for type variables based on traversing the control flow graph. The conditions for activating in this traversal are currently: on a binary equality expression when one of the sides is a literal and the other side is an identifier annotated with a type parameter defined in the function, which is bounded by a union of singleton types. Currently this type mapper is an optional parameter and I have passed it around to make the use cases in the test cases (tests/cases/compiler/depTypeLikeFun.ts). Likely the type mapper needs to be passed around in more situations to make other complex scenarios work.

This type mapper is then used inside the getSimplifiedIndexedAccessType, under the following conditions: object type is concrete and index type is a type parameter able to index the object.

Some next steps regarding this implementation:

  • I have noticed that enabling the binding of return statements had some impact on two tests related to unreachable code: codeFixUnreachable and unreachableJavascriptChecked. This should probably investigated to make sure those tests pass again.
  • Check performance impact of this implementation to see whether we need to tinker a bit more on it (for example adding some form of caching when traversing the control flow graph).
  • Make sure the additional tests cover all positive/negative cases we want it to cover.
  • If we want to extend the feature and pass the getTypeMapper around in more situations, I think we need to make sure that type parameters in negative positions are not substituted by the type mapper.
  • Finish implementation regarding: unhandled control flow cases (such as switch statements, and going through antecedent statements of currently unhandled cases), non-string literals in control flow check, more complicated checks (equality checks nested in and/or for example), etc.

@jack-williams @RyanCavanaugh @DanielRosenwasser Feedback / Comments are welcome.

@sandersn
Copy link
Member

This experiment is pretty old, so I'm going to close it to reduce the number of open PRs.

@sandersn sandersn closed this May 24, 2022
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experiment A fork with an experimental idea which might not make it into master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants