Skip to content

Conversation

@Andarist
Copy link
Contributor

closes#61659

CopilotAI review requested due to automatic review settings May 5, 2025 09:54
@AndaristAndaristforce-pushed the avoid-circularity-on-any-unknown-target-props branch from c5da502 to 8289db7CompareMay 5, 2025 09:54
@github-project-automationgithub-project-automationbot moved this to Not started in PR BacklogMay 5, 2025
@typescript-bottypescript-bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels May 5, 2025
Copy link
Contributor

CopilotAI 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).

  • Introduces a new condition in isPropertySymbolTypeRelated that returns Ternary.True when the effective target’s flags indicate “any” (or “any”/“unknown” depending on the relation), thereby avoiding unnecessary resolution of the source property type.
  • Adds an explanatory comment to document this behavior per issue #61659.
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

@AndaristAndaristforce-pushed the avoid-circularity-on-any-unknown-target-props branch from 8289db7 to 540e84dCompareMay 5, 2025 09:59
@LukeAbby
Copy link

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
ContributorAuthor

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

CommandStatusResults
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
MetricbaselineprDeltaBestWorstp-value
Compiler-Unions - node (v18.15.0, x64)
Errors3434~~~p=1.000 n=6
Symbols62,39062,390~~~p=1.000 n=6
Types50,39550,395~~~p=1.000 n=6
Memory used196,059k (± 0.74%)196,078k (± 0.73%)~193,153k196,688kp=0.810 n=6
Parse Time1.60s (± 1.65%)1.60s (± 1.83%)~1.55s1.64sp=0.871 n=6
Bind Time0.89s0.89s (± 2.30%)~0.87s0.91sp=1.000 n=6
Check Time11.79s (± 0.57%)11.79s (± 0.55%)~11.73s11.92sp=0.872 n=6
Emit Time3.29s (± 1.07%)3.31s (± 1.17%)~3.26s3.36sp=0.374 n=6
Total Time17.56s (± 0.46%)17.59s (± 0.60%)~17.49s17.74sp=0.748 n=6
angular-1 - node (v18.15.0, x64)
Errors5656~~~p=1.000 n=6
Symbols949,240949,249+9 (+ 0.00%)~~p=0.001 n=6
Types411,065411,061-4 (- 0.00%)~~p=0.001 n=6
Memory used1,225,308k (± 0.00%)1,225,239k (± 0.00%)-70k (- 0.01%)1,225,195k1,225,288kp=0.031 n=6
Parse Time8.04s (± 1.13%)8.03s (± 0.82%)~7.94s8.11sp=0.872 n=6
Bind Time2.29s (± 1.06%)2.27s (± 0.37%)~2.27s2.29sp=0.120 n=6
Check Time38.08s (± 0.20%)38.20s (± 0.44%)~37.95s38.42sp=0.149 n=6
Emit Time18.31s (± 0.45%)18.33s (± 0.55%)~18.20s18.46sp=0.575 n=6
Total Time66.72s (± 0.20%)66.85s (± 0.19%)~66.70s67.07sp=0.173 n=6
mui-docs - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols2,439,9292,439,624-305 (- 0.01%)~~p=0.001 n=6
Types872,556872,323-233 (- 0.03%)~~p=0.001 n=6
Memory used2,448,472k (± 0.00%)2,448,203k (± 0.00%)-269k (- 0.01%)2,448,145k2,448,269kp=0.005 n=6
Parse Time10.59s (± 0.27%)10.57s (± 0.33%)~10.51s10.61sp=1.000 n=6
Bind Time2.69s (± 0.72%)2.71s (± 0.96%)~2.67s2.75sp=0.168 n=6
Check Time87.13s (± 1.64%)87.87s (± 3.35%)~86.10s93.77sp=0.936 n=6
Emit Time0.37s (± 2.22%)0.37s (± 3.17%)~0.36s0.39sp=1.000 n=6
Total Time100.77s (± 1.43%)101.52s (± 2.92%)~99.68s107.46sp=0.689 n=6
self-build-src - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,228,0521,228,052~~~p=1.000 n=6
Types267,262267,263+1 (+ 0.00%)~~p=0.001 n=6
Memory used2,972,556k (±10.03%)2,850,877k (±13.24%)~2,363,094k3,095,377kp=0.936 n=6
Parse Time6.70s (± 0.96%)6.63s (± 1.54%)~6.49s6.75sp=0.230 n=6
Bind Time2.14s (± 2.20%)2.15s (± 1.44%)~2.12s2.20sp=0.872 n=6
Check Time42.86s (± 0.47%)42.91s (± 0.41%)~42.63s43.11sp=0.936 n=6
Emit Time3.52s (± 2.38%)3.50s (± 1.89%)~3.43s3.59sp=0.521 n=6
Total Time55.22s (± 0.62%)55.20s (± 0.39%)~54.80s55.37sp=0.378 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,228,0521,228,052~~~p=1.000 n=6
Types267,262267,263+1 (+ 0.00%)~~p=0.001 n=6
Memory used2,917,476k (±12.85%)2,821,496k (±13.27%)~2,430,261k3,160,100kp=0.471 n=6
Parse Time8.57s (± 1.79%)8.53s (± 1.30%)~8.42s8.68sp=0.374 n=6
Bind Time2.68s (± 1.91%)2.67s (± 1.58%)~2.62s2.73sp=0.630 n=6
Check Time52.93s (± 0.63%)52.98s (± 0.71%)~52.35s53.36sp=0.936 n=6
Emit Time4.29s (± 2.38%)4.34s (± 2.35%)~4.18s4.44sp=0.423 n=6
Total Time68.47s (± 0.70%)68.52s (± 0.61%)~67.95s69.09sp=0.936 n=6
self-compiler - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols263,419263,419~~~p=1.000 n=6
Types107,098107,099+1 (+ 0.00%)~~p=0.001 n=6
Memory used441,811k (± 0.02%)441,830k (± 0.02%)~441,712k441,938kp=0.689 n=6
Parse Time3.53s (± 1.04%)3.54s (± 1.09%)~3.47s3.57sp=0.376 n=6
Bind Time1.33s (± 1.10%)1.33s (± 0.57%)~1.32s1.34sp=0.620 n=6
Check Time19.10s (± 0.24%)19.04s (± 0.34%)~18.98s19.12sp=0.253 n=6
Emit Time1.53s (± 1.01%)1.55s (± 1.33%)~1.53s1.59sp=0.052 n=6
Total Time25.49s (± 0.24%)25.47s (± 0.32%)~25.37s25.59sp=0.747 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors7171~~~p=1.000 n=6
Symbols225,981225,981~~~p=1.000 n=6
Types94,35694,356~~~p=1.000 n=6
Memory used371,338k (± 0.04%)371,454k (± 0.06%)~371,205k371,761kp=0.630 n=6
Parse Time3.61s (± 0.69%)3.60s (± 0.21%)~3.59s3.61sp=0.415 n=6
Bind Time1.99s (± 0.82%)1.97s (± 1.11%)~1.94s2.00sp=0.076 n=6
Check Time20.49s (± 0.15%)20.55s (± 0.22%)~20.50s20.62sp=0.065 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time26.09s (± 0.19%)26.12s (± 0.23%)~26.06s26.21sp=0.688 n=6
vscode - node (v18.15.0, x64)
Errors5151~~~p=1.000 n=6
Symbols3,419,8963,419,897+1 (+ 0.00%)~~p=0.001 n=6
Types1,154,0131,153,984-29 (- 0.00%)~~p=0.001 n=6
Memory used3,472,378k (± 0.01%)3,472,416k (± 0.00%)~3,472,198k3,472,712kp=0.689 n=6
Parse Time18.39s (± 0.82%)18.26s (± 1.01%)~18.05s18.56sp=0.173 n=6
Bind Time5.83s (± 0.46%)5.84s (± 0.68%)~5.79s5.89sp=0.808 n=6
Check Time118.16s (± 3.52%)114.37s (± 1.55%)~113.05s117.90sp=0.298 n=6
Emit Time37.32s (± 2.42%)36.86s (± 1.97%)~36.23s38.29sp=0.630 n=6
Total Time179.70s (± 2.62%)175.33s (± 1.45%)~173.73s180.47sp=0.173 n=6
webpack - node (v18.15.0, x64)
Errors22~~~p=1.000 n=6
Symbols317,848317,854+6 (+ 0.00%)~~p=0.001 n=6
Types140,485140,476-9 (- 0.01%)~~p=0.001 n=6
Memory used473,064k (± 0.04%)473,112k (± 0.02%)~472,940k473,189kp=0.575 n=6
Parse Time5.16s (± 0.51%)5.18s (± 0.35%)~5.15s5.20sp=0.101 n=6
Bind Time2.27s (± 1.94%)2.23s (± 1.05%)~2.20s2.26sp=0.091 n=6
Check Time25.92s (± 0.34%)25.93s (± 0.41%)~25.79s26.10sp=0.936 n=6
Emit Time0.00s (±244.70%)0.00s~~~p=0.405 n=6
Total Time33.36s (± 0.36%)33.34s (± 0.31%)~33.22s33.51sp=0.748 n=6
xstate-main - node (v18.15.0, x64)
Errors55~~~p=1.000 n=6
Symbols570,733559,890-10,843 (- 1.90%)~~p=0.001 n=6
Types191,446191,112-334 (- 0.17%)~~p=0.001 n=6
Memory used501,304k (± 0.01%)496,297k (± 0.04%)-5,007k (- 1.00%)495,921k496,465kp=0.005 n=6
Parse Time3.48s (± 0.44%)3.48s (± 0.76%)~3.45s3.52sp=0.808 n=6
Bind Time1.23s (± 1.40%)1.24s (± 0.61%)~1.23s1.25sp=0.087 n=6
Check Time20.17s (± 0.26%)20.23s (± 2.86%)~19.95s21.41sp=0.092 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time24.88s (± 0.19%)24.96s (± 2.24%)~24.65s26.09sp=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)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

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-automationgithub-project-automationbot moved this from Not started to Needs merge in PR BacklogJun 6, 2025
@jakebailey
Copy link
Member

Alas, this needs a merge with main.

@typescript-bottypescript-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
ContributorAuthor

@jakebailey synced with main

@jakebailey
Copy link
Member

Seems like there are more baseline diffs.

@AndaristAndaristforce-pushed the avoid-circularity-on-any-unknown-target-props branch from fbe29ad to a563d6bCompareJune 6, 2025 21:11
@Andarist
Copy link
ContributorAuthor

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

@jakebaileyjakebailey merged commit 355b9e0 into microsoft:mainJun 6, 2025
32 checks passed
@github-project-automationgithub-project-automationbot moved this from Needs merge to Done in PR BacklogJun 6, 2025
@microsoftmicrosoft locked as resolved and limited conversation to collaborators Dec 9, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog BugPRs 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

@Andarist@LukeAbby@RyanCavanaugh@jakebailey@typescript-bot@colinhacks