Skip to content

Avoid resolving source prop type when the target is unknown/any #61660

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

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented May 5, 2025

closes #61659

@Copilot Copilot AI review requested due to automatic review settings May 5, 2025 09:54
@Andarist Andarist force-pushed the avoid-circularity-on-any-unknown-target-props branch from c5da502 to 8289db7 Compare May 5, 2025 09:54
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog May 5, 2025
@typescript-bot typescript-bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels May 5, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the performance and accuracy of type checking for property symbols by short‐circuiting the relation check when the target type is “any” (or “any”/“unknown” when not using strict subtype relation).

Files not reviewed (5)
  • tests/baselines/reference/multiline.types: Language not supported
  • tests/baselines/reference/noCircularitySelfReferentialGetter1.symbols: Language not supported
  • tests/baselines/reference/noCircularitySelfReferentialGetter1.types: Language not supported
  • tests/baselines/reference/noCircularitySelfReferentialGetter2.symbols: Language not supported
  • tests/baselines/reference/noCircularitySelfReferentialGetter2.types: Language not supported

@Andarist Andarist force-pushed the avoid-circularity-on-any-unknown-target-props branch from 8289db7 to 540e84d Compare May 5, 2025 09:59
@LukeAbby
Copy link

LukeAbby commented May 5, 2025

I will just pop in here to note that this would presumably hep with a number of circularities I've experienced.

@RyanCavanaugh
Copy link
Member

@typescript-bot test it

@Andarist
Copy link
Contributor Author

Andarist commented May 7, 2025

@RyanCavanaugh it looks like the bot didnt pick this up. Could you try again?

@jakebailey
Copy link
Member

The bot is broken, I am fixing it.

@jakebailey
Copy link
Member

@typescript-bot test it

1 similar comment
@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 7, 2025

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

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

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests with tsc comparing main and refs/pull/61660/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 34 34 ~ ~ ~ p=1.000 n=6
Symbols 62,390 62,390 ~ ~ ~ p=1.000 n=6
Types 50,395 50,395 ~ ~ ~ p=1.000 n=6
Memory used 196,059k (± 0.74%) 196,078k (± 0.73%) ~ 193,153k 196,688k p=0.810 n=6
Parse Time 1.60s (± 1.65%) 1.60s (± 1.83%) ~ 1.55s 1.64s p=0.871 n=6
Bind Time 0.89s 0.89s (± 2.30%) ~ 0.87s 0.91s p=1.000 n=6
Check Time 11.79s (± 0.57%) 11.79s (± 0.55%) ~ 11.73s 11.92s p=0.872 n=6
Emit Time 3.29s (± 1.07%) 3.31s (± 1.17%) ~ 3.26s 3.36s p=0.374 n=6
Total Time 17.56s (± 0.46%) 17.59s (± 0.60%) ~ 17.49s 17.74s p=0.748 n=6
angular-1 - node (v18.15.0, x64)
Errors 56 56 ~ ~ ~ p=1.000 n=6
Symbols 949,240 949,249 +9 (+ 0.00%) ~ ~ p=0.001 n=6
Types 411,065 411,061 -4 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 1,225,308k (± 0.00%) 1,225,239k (± 0.00%) -70k (- 0.01%) 1,225,195k 1,225,288k p=0.031 n=6
Parse Time 8.04s (± 1.13%) 8.03s (± 0.82%) ~ 7.94s 8.11s p=0.872 n=6
Bind Time 2.29s (± 1.06%) 2.27s (± 0.37%) ~ 2.27s 2.29s p=0.120 n=6
Check Time 38.08s (± 0.20%) 38.20s (± 0.44%) ~ 37.95s 38.42s p=0.149 n=6
Emit Time 18.31s (± 0.45%) 18.33s (± 0.55%) ~ 18.20s 18.46s p=0.575 n=6
Total Time 66.72s (± 0.20%) 66.85s (± 0.19%) ~ 66.70s 67.07s p=0.173 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,439,929 2,439,624 -305 (- 0.01%) ~ ~ p=0.001 n=6
Types 872,556 872,323 -233 (- 0.03%) ~ ~ p=0.001 n=6
Memory used 2,448,472k (± 0.00%) 2,448,203k (± 0.00%) -269k (- 0.01%) 2,448,145k 2,448,269k p=0.005 n=6
Parse Time 10.59s (± 0.27%) 10.57s (± 0.33%) ~ 10.51s 10.61s p=1.000 n=6
Bind Time 2.69s (± 0.72%) 2.71s (± 0.96%) ~ 2.67s 2.75s p=0.168 n=6
Check Time 87.13s (± 1.64%) 87.87s (± 3.35%) ~ 86.10s 93.77s p=0.936 n=6
Emit Time 0.37s (± 2.22%) 0.37s (± 3.17%) ~ 0.36s 0.39s p=1.000 n=6
Total Time 100.77s (± 1.43%) 101.52s (± 2.92%) ~ 99.68s 107.46s p=0.689 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,228,052 1,228,052 ~ ~ ~ p=1.000 n=6
Types 267,262 267,263 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,972,556k (±10.03%) 2,850,877k (±13.24%) ~ 2,363,094k 3,095,377k p=0.936 n=6
Parse Time 6.70s (± 0.96%) 6.63s (± 1.54%) ~ 6.49s 6.75s p=0.230 n=6
Bind Time 2.14s (± 2.20%) 2.15s (± 1.44%) ~ 2.12s 2.20s p=0.872 n=6
Check Time 42.86s (± 0.47%) 42.91s (± 0.41%) ~ 42.63s 43.11s p=0.936 n=6
Emit Time 3.52s (± 2.38%) 3.50s (± 1.89%) ~ 3.43s 3.59s p=0.521 n=6
Total Time 55.22s (± 0.62%) 55.20s (± 0.39%) ~ 54.80s 55.37s p=0.378 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,228,052 1,228,052 ~ ~ ~ p=1.000 n=6
Types 267,262 267,263 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,917,476k (±12.85%) 2,821,496k (±13.27%) ~ 2,430,261k 3,160,100k p=0.471 n=6
Parse Time 8.57s (± 1.79%) 8.53s (± 1.30%) ~ 8.42s 8.68s p=0.374 n=6
Bind Time 2.68s (± 1.91%) 2.67s (± 1.58%) ~ 2.62s 2.73s p=0.630 n=6
Check Time 52.93s (± 0.63%) 52.98s (± 0.71%) ~ 52.35s 53.36s p=0.936 n=6
Emit Time 4.29s (± 2.38%) 4.34s (± 2.35%) ~ 4.18s 4.44s p=0.423 n=6
Total Time 68.47s (± 0.70%) 68.52s (± 0.61%) ~ 67.95s 69.09s p=0.936 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 263,419 263,419 ~ ~ ~ p=1.000 n=6
Types 107,098 107,099 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 441,811k (± 0.02%) 441,830k (± 0.02%) ~ 441,712k 441,938k p=0.689 n=6
Parse Time 3.53s (± 1.04%) 3.54s (± 1.09%) ~ 3.47s 3.57s p=0.376 n=6
Bind Time 1.33s (± 1.10%) 1.33s (± 0.57%) ~ 1.32s 1.34s p=0.620 n=6
Check Time 19.10s (± 0.24%) 19.04s (± 0.34%) ~ 18.98s 19.12s p=0.253 n=6
Emit Time 1.53s (± 1.01%) 1.55s (± 1.33%) ~ 1.53s 1.59s p=0.052 n=6
Total Time 25.49s (± 0.24%) 25.47s (± 0.32%) ~ 25.37s 25.59s p=0.747 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 71 71 ~ ~ ~ p=1.000 n=6
Symbols 225,981 225,981 ~ ~ ~ p=1.000 n=6
Types 94,356 94,356 ~ ~ ~ p=1.000 n=6
Memory used 371,338k (± 0.04%) 371,454k (± 0.06%) ~ 371,205k 371,761k p=0.630 n=6
Parse Time 3.61s (± 0.69%) 3.60s (± 0.21%) ~ 3.59s 3.61s p=0.415 n=6
Bind Time 1.99s (± 0.82%) 1.97s (± 1.11%) ~ 1.94s 2.00s p=0.076 n=6
Check Time 20.49s (± 0.15%) 20.55s (± 0.22%) ~ 20.50s 20.62s p=0.065 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 26.09s (± 0.19%) 26.12s (± 0.23%) ~ 26.06s 26.21s p=0.688 n=6
vscode - node (v18.15.0, x64)
Errors 51 51 ~ ~ ~ p=1.000 n=6
Symbols 3,419,896 3,419,897 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 1,154,013 1,153,984 -29 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 3,472,378k (± 0.01%) 3,472,416k (± 0.00%) ~ 3,472,198k 3,472,712k p=0.689 n=6
Parse Time 18.39s (± 0.82%) 18.26s (± 1.01%) ~ 18.05s 18.56s p=0.173 n=6
Bind Time 5.83s (± 0.46%) 5.84s (± 0.68%) ~ 5.79s 5.89s p=0.808 n=6
Check Time 118.16s (± 3.52%) 114.37s (± 1.55%) ~ 113.05s 117.90s p=0.298 n=6
Emit Time 37.32s (± 2.42%) 36.86s (± 1.97%) ~ 36.23s 38.29s p=0.630 n=6
Total Time 179.70s (± 2.62%) 175.33s (± 1.45%) ~ 173.73s 180.47s p=0.173 n=6
webpack - node (v18.15.0, x64)
Errors 2 2 ~ ~ ~ p=1.000 n=6
Symbols 317,848 317,854 +6 (+ 0.00%) ~ ~ p=0.001 n=6
Types 140,485 140,476 -9 (- 0.01%) ~ ~ p=0.001 n=6
Memory used 473,064k (± 0.04%) 473,112k (± 0.02%) ~ 472,940k 473,189k p=0.575 n=6
Parse Time 5.16s (± 0.51%) 5.18s (± 0.35%) ~ 5.15s 5.20s p=0.101 n=6
Bind Time 2.27s (± 1.94%) 2.23s (± 1.05%) ~ 2.20s 2.26s p=0.091 n=6
Check Time 25.92s (± 0.34%) 25.93s (± 0.41%) ~ 25.79s 26.10s p=0.936 n=6
Emit Time 0.00s (±244.70%) 0.00s ~ ~ ~ p=0.405 n=6
Total Time 33.36s (± 0.36%) 33.34s (± 0.31%) ~ 33.22s 33.51s p=0.748 n=6
xstate-main - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 570,733 559,890 -10,843 (- 1.90%) ~ ~ p=0.001 n=6
Types 191,446 191,112 -334 (- 0.17%) ~ ~ p=0.001 n=6
Memory used 501,304k (± 0.01%) 496,297k (± 0.04%) -5,007k (- 1.00%) 495,921k 496,465k p=0.005 n=6
Parse Time 3.48s (± 0.44%) 3.48s (± 0.76%) ~ 3.45s 3.52s p=0.808 n=6
Bind Time 1.23s (± 1.40%) 1.24s (± 0.61%) ~ 1.23s 1.25s p=0.087 n=6
Check Time 20.17s (± 0.26%) 20.23s (± 2.86%) ~ 19.95s 21.41s p=0.092 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.88s (± 0.19%) 24.96s (± 2.24%) ~ 24.65s 26.09s p=0.108 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 400 repos with tsc comparing main and refs/pull/61660/merge:

Everything looks good!

@colinhacks
Copy link

colinhacks commented May 28, 2025

This would be very high-impact for Zod :) I'm currently doing some regrettably hacky stuff to get getter-based recursive object schemas working. There's a lot of interest in the kind of things this would unlock, and I'd like for Zod to stay on a happier path to achieve this.

For a more detailed writeup on the motivations for this change, see my original issue: #61659

@jakebailey
Copy link
Member

We talked about this in the design meeting and are going to take this for 5.9. it's pretty simple and easily portable over to Go in the future.

The rationale is largely that we could have already made this change "accidentally" for other reasons (e.g., as a perf optimization), and that we have already done this kind of thing in other parts of relations for similar reasons. For example, actually going into isRelatedTo already quick checks against any/unknown.

This sort of thing is probably worth applying to other places, wherever those are.

A downside however is that there's technically nothing special about having evaluated the target type versus the source type. There's a world in which the source is never and so maybe we should skip checking the target! So, it's just down to guesswork at that point.

I'll also note that at least for Zod, this means that some functionality will require 5.9+; hopefully this is optional functionality, and not something like "sorry, all zod users need to sue 5.9 now" 😄


We also thought that (some day) it would make sense for relations to take functions as arguments rather than fully resolved types, given in many conditions we could avoid things, but that's a totally different idea.

@github-project-automation github-project-automation bot moved this from Not started to Needs merge in PR Backlog Jun 6, 2025
@jakebailey
Copy link
Member

Alas, this needs a merge with main.

@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jun 6, 2025
@Andarist
Copy link
Contributor Author

Andarist commented Jun 6, 2025

@jakebailey synced with main

@jakebailey
Copy link
Member

Seems like there are more baseline diffs.

@Andarist Andarist force-pushed the avoid-circularity-on-any-unknown-target-props branch from fbe29ad to a563d6b Compare June 6, 2025 21:11
@Andarist
Copy link
Contributor Author

Andarist commented Jun 6, 2025

@jakebailey Ok, I actually re-run the whole test suite locally now and pushed the updated baselines 😅

@jakebailey jakebailey merged commit 355b9e0 into microsoft:main Jun 6, 2025
32 checks passed
@github-project-automation github-project-automation bot moved this from Needs merge to Done in PR Backlog Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Support cyclical type inference of self-referential data structures, when subject to some assignability constraints
6 participants