Skip to content

[ty] Avoid definition lookups in recursive TypedDict comparisons - #30444

Draft
charliermarsh wants to merge 2 commits into
mainfrom
charlie/ty-pydantic-cold-check
Draft

charliermarsh wants to merge 2 commits into
mainfrom
charlie/ty-pydantic-cold-check

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Summary

When ty compares two TypedDicts, it checks whether it has already seen the same recursive comparison. Just ruling out a match used to require looking up both class definitions in the semantic index. On Pydantic, this was hot even when comparing unrelated classes.

We now compare the class body scopes directly. Each static class has its own body scope, even if decorators change the inferred class. The cycle detector still confirms a possible match as before. No new cache is needed.

Project Base instructions PR instructions Change Paired range
Black 3,190,053,839.5 3,188,241,010.5 -0.06% -0.25% to +0.14%
discord.py 8,259,374,385 8,273,184,860.5 +0.17% +0.13% to +0.21%
Django 14,001,184,223.5 14,011,332,236.5 +0.07% 0.00% to +0.15%
FastAPI 3,025,802,232.5 3,008,598,981 -0.57% -0.82% to -0.32%
Home Assistant 160,215,011,062 160,207,933,299 -0.00% -0.01% to +0.00%
HTTPX 1,673,282,803 1,673,246,216.5 -0.00% -0.22% to +0.22%
isort 1,843,059,788 1,844,450,255 +0.08% -0.00% to +0.16%
Jinja 1,928,721,892 1,926,416,699 -0.12% -0.30% to +0.07%
NumPy 8,958,396,167.5 8,969,914,964 +0.13% -0.17% to +0.43%
OpenAI Python SDK 16,000,188,103 15,988,082,034 -0.08% -0.10% to -0.05%
pandas 30,312,056,762.5 30,352,688,313.5 +0.13% +0.01% to +0.26%
pandas-stubs 2,947,385,062 2,948,535,288 +0.04% -0.16% to +0.24%
Prefect 4,907,754,594.5 4,905,679,459.5 -0.04% -0.06% to -0.02%
pytest 8,849,672,821.5 8,856,795,249.5 +0.08% +0.07% to +0.09%
PyTorch 98,301,163,943 98,225,138,861 -0.08% -0.12% to -0.04%
Rich 2,709,709,778.5 2,714,149,963.5 +0.16% -0.08% to +0.41%
SQLAlchemy 21,857,396,126 21,845,368,544.5 -0.06% -0.16% to +0.05%
SymPy 46,743,486,541 46,744,399,446 0.00% -0.09% to +0.09%
aiohttp 4,161,325,878 4,162,546,498.5 +0.03% -0.00% to +0.06%
Ansible 14,608,429,663 14,596,174,263 -0.08% -0.18% to +0.01%
botocore 3,003,082,894.5 3,002,930,681 -0.01% -0.02% to +0.01%
Celery 4,825,905,235.5 4,830,880,175.5 +0.10% 0.00% to +0.21%
Dask 36,489,353,458 36,468,164,350 -0.06% -0.06% to -0.06%
NetworkX 16,654,074,392.5 16,661,866,206 +0.05% +0.04% to +0.05%
Pydantic 15,921,444,387 14,374,354,228.5 -9.72% -9.73% to -9.70%
scikit-learn 77,952,541,396.5 77,935,694,925.5 -0.02% -0.05% to +0.01%
Scrapy 8,965,385,292.5 8,961,380,316 -0.04% -0.14% to +0.05%
Transformers 105,264,942,428.5 105,294,114,319 +0.03% -0.05% to +0.10%

When testing whether two active types could have the same recursive identity, compare their static class body scopes. The scope already identifies the class definition; fetching the definition via the semantic index is unnecessary. Synthesized and dynamic TypedDicts use exact identity, which has already been checked.
@charliermarsh charliermarsh added ty The ty type checker performance Potential performance improvement labels Nov 15, 2026 — with ChatGPT Codex Connector
@astral-automations-bot

astral-automations-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 98.60%. The percentage of expected errors that received a diagnostic held steady at 98.86%. The number of fully passing files held steady at 137/146.

Results for 5d9752c · Workflow run

@astral-automations-bot

astral-automations-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Memory usage report

Memory usage unchanged ✅


Results for 5d9752c · Workflow run

@astral-automations-bot

astral-automations-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff · Timing results


Results for 5d9752c · Workflow run

This branch was successfully deployed

1 active deployment
automations — 5d9752c4 Deployed Nov 15, 2026 by charliermarsh via security-review / security review #98664
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Potential performance improvement ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant