Skip to content

[ty] Index TypedDict identities when building unions - #28385

Draft
charliermarsh wants to merge 1 commit into
mainfrom
charlie/codex-ty-typed-dict-union-index
Draft

[ty] Index TypedDict identities when building unions#28385
charliermarsh wants to merge 1 commit into
mainfrom
charlie/codex-ty-typed-dict-union-index

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

Unions containing only TypedDicts retain distinct dictionary types by identity, but adding each member still scans the existing members for duplicates. We now maintain an identity set alongside the ordered member vector, avoiding repeated scans as these unions grow.

The set is allocated only after a second distinct dictionary is added and is discarded when a non-TypedDict member requires ordinary union simplification. Flattened unions and expanded aliases preserve first-occurrence order and recursion metadata.

Against e579b84aba, the existing Pydantic CodSpeed walltime benchmark measured 2.708 s before and 2.591 s after this change alone. This is a 4.3% reduction in elapsed time in this sample. These local measurements use one process pair with six samples per process and two iterations per sample.

@charliermarsh charliermarsh added the ty Multi-file analysis & type inference label Sep 7, 2026
@astral-sh-bot

astral-sh-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 97.84%. The percentage of expected errors that received a diagnostic held steady at 96.45%. The number of fully passing files held steady at 128/145.

@astral-sh-bot

astral-sh-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@codspeed-hq

codspeed-hq Bot commented Sep 7, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.85%

❌ 2 regressed benchmarks
✅ 138 untouched benchmarks
⏩ 84 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ty_micro[inherited_recursive_protocol_diagnostic] 7.8 s 8.2 s -4.9%
Simulation ty_micro[inherited_recursive_protocol_constructor] 7.8 s 8.1 s -4.8%

Tip

Investigate this regression with the CodSpeed MCP and your agent.


Comparing charlie/codex-ty-typed-dict-union-index (f670cde) with main (e579b84)

Open in CodSpeed

Footnotes

  1. 84 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant