Skip to content

Short-circuit isTypeVarSame subtype checks - #11681

Open
Bill Schnurr (bschnurr) wants to merge 1 commit into
microsoft:mainfrom
bschnurr:perf/type-utils-short-circuit
Open

Short-circuit isTypeVarSame subtype checks#11681
Bill Schnurr (bschnurr) wants to merge 1 commit into
microsoft:mainfrom
bschnurr:perf/type-utils-short-circuit

Conversation

@bschnurr

@bschnurr Bill Schnurr (bschnurr) commented Aug 26, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixes allSubtypes so union checks return callback results.
  • Delegates directly to Array.every for allocation-free early termination.
  • Uses allSubtypes in isTypeVarSame to stop at the first incompatible subtype instead of walking the remaining union entries with no-op callbacks.
  • Preserves someSubtypes and adds direct unit coverage for both helpers.

This is the safe typeUtils portion split from #11419. It intentionally excludes the literal, tuple, derivesFromAnyOrUnknown, and NoReturn early exits that produced mypy_primer differences.

Validation

  • pnpm exec jest typeUtils.test --forceExit
  • pnpm run build
  • pnpm run check:prettier
  • pnpm run check:eslint
  • full hosted validation: 16 checks passed
  • exact-head mypy_primer rerun: all eight diff artifacts empty

@bschnurr

Copy link
Copy Markdown
Member Author

/benchmark

@rchiodo

Rich Chiodo (rchiodo) commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

🔒 Automated review in progress — Rich Chiodo (@rchiodo) is auto-reviewing this PR.

@github-actions

This comment has been minimized.

@rchiodo

Copy link
Copy Markdown
Collaborator

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

@rchiodo Rich Chiodo (rchiodo) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved via Review Center.

@rchiodo Rich Chiodo (rchiodo) added the review-auto:approved Automated review: no blocking findings (approval posted). label Aug 26, 2026
@github-actions

This comment has been minimized.

@bschnurr
Bill Schnurr (bschnurr) force-pushed the perf/type-utils-short-circuit branch from 72e74f2 to 2901d5f Compare August 26, 2026 18:36
@bschnurr Bill Schnurr (bschnurr) changed the title Fix and short-circuit subtype helper paths Short-circuit subtype helper paths Aug 26, 2026
@rchiodo

Copy link
Copy Markdown
Collaborator

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

@github-actions

This comment has been minimized.

@bschnurr
Bill Schnurr (bschnurr) force-pushed the perf/type-utils-short-circuit branch from 2901d5f to ce7460c Compare August 26, 2026 19:30
@bschnurr Bill Schnurr (bschnurr) changed the title Short-circuit subtype helper paths Fix allSubtypes callback handling Aug 26, 2026
@rchiodo

Copy link
Copy Markdown
Collaborator

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

@github-actions

This comment has been minimized.

@bschnurr

Copy link
Copy Markdown
Member Author

/benchmark

Fix allSubtypes callback handling and delegate union traversal directly to Array.every. Use it in isTypeVarSame to stop the subtype scan at the first incompatibility instead of invoking no-op callbacks for the remainder.

Add direct allSubtypes and someSubtypes coverage.
@bschnurr
Bill Schnurr (bschnurr) force-pushed the perf/type-utils-short-circuit branch from ce7460c to c49ce2f Compare August 26, 2026 23:47
@bschnurr Bill Schnurr (bschnurr) changed the title Fix allSubtypes callback handling Short-circuit isTypeVarSame subtype checks Aug 26, 2026
@rchiodo

Copy link
Copy Markdown
Collaborator

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

Result: could-not-verify

Summary: Verification could not run because no trusted `microsoft/pyright` sandbox image was configured and local execution was unauthorized. The PR adds focused coverage for union short-circuiting and non-union callbacks in `allSubtypes` and `someSubtypes`. No meaningful test execution occurred, so the verdict is **could-not-verify**.

Test runs: 1 not run

  • ⚠️ Not run | typeUtils unit tests | pnpm exec jest typeUtils.test --runInBand
⚠️ typeUtils unit tests diagnostic output
Container verification could not start: no trusted sandbox image is configured for microsoft/pyright; local execution was not authorized for this PR HEAD.

@github-actions

This comment has been minimized.

@bschnurr

Copy link
Copy Markdown
Member Author

/benchmark

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@bschnurr

Copy link
Copy Markdown
Member Author

/benchmark

@github-actions

Copy link
Copy Markdown
Contributor

Type checker benchmark

🟢 No performance regressions detected.

Regression threshold: 20.0%
Variance guard: >1.0s time and >100.0 MB memory

Package Checker Files checked Time Time delta Peak memory Memory delta Status
ansible pyright 583 18.951s -12.5% 1168.3 MB +5.2% 🟢 Pass
click pyright 17 2.706s -6.9% 361.7 MB +0.2% 🟢 Pass
homeassistant pyright 9850 137.064s -13.4% 6196.9 MB +0.1% 🟢 Pass
numpy pyright 356 37.361s -14.0% 1847.0 MB -0.2% 🟢 Pass
pandas pyright 1459 866.065s -12.4% 4451.5 MB +0.4% 🟢 Pass
pytest pyright 243 11.420s -9.2% 891.8 MB -4.2% 🟢 Pass
requests pyright 19 2.155s -6.3% 343.7 MB -1.0% 🟢 Pass
torch pyright 2400 136.841s -11.0% 5182.0 MB +5.9% 🟢 Pass
transformers pyright 2901 113.567s -15.6% 5250.5 MB +2.3% 🟢 Pass

Pyright stats

Package Parsed/bound Checked Find Read Tokenize Parse Imports Bind Check Cycles
ansible 989 583 0.030s 0.100s 0.450s 0.650s 0.220s 0.860s 16.130s 0.000s
click 111 17 0.000s 0.020s 0.120s 0.160s 0.030s 0.230s 1.840s 0.000s
homeassistant 11138 9850 0.330s 0.900s 3.020s 4.280s 2.080s 6.270s 117.340s 0.000s
numpy 603 356 0.010s 0.070s 0.400s 0.620s 0.230s 0.780s 34.760s 0.000s
pandas 1895 1459 0.050s 0.270s 1.200s 1.850s 0.290s 2.220s 859.110s 0.000s
pytest 542 243 0.010s 0.070s 0.360s 0.440s 0.090s 0.630s 9.420s 0.000s
requests 168 19 0.000s 0.020s 0.110s 0.180s 0.050s 0.240s 1.280s 0.000s
torch 3076 2400 0.110s 0.560s 2.840s 3.100s 0.580s 4.410s 123.890s 0.000s
transformers 3534 2901 0.100s 0.430s 2.680s 3.180s 0.990s 8.650s 98.000s 0.000s

@heejaechang

Copy link
Copy Markdown
Collaborator

✅ Pyright CLI QA — c49ce2fb — verdict: green

Automated CLI checks compared this change with its base revision.
4 focused check(s) completed.

No new behavior difference was detected by the completed CLI checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants