Repository navigation
Conversation
Use direct class checks in TypeSet.collect_referenced_types and keep the named-type cast for static type checking only. Bind recursive calls only for types with references and skip empty built-in argument maps. Preserve traversal order, type identity, lazy lookups, and custom mappings. The native suite, seven benchmark tests, Ruff, and mypy pass. Co-Authored-By: Aiden <[email protected]>
Merging this PR will improve performance by 77.43%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing |
|
Thanks! I applied this as Randomized schemas gave results identical to main, including the error cases. On Python 3.14 I measured about 23% less time for recreating the GitHub schema and about 2% for building a client schema. I left out the This is part of 3.3.2. |
TL;DR
TypeSet.collect_referenced_typeswhen rebuilding a schema.PYTHONPATH=src python -m pytest -q: 3,625 passed, 18 skipped.Refs #300
What & Why
Schema construction repeatedly called wrapper and type-check helpers, including for references already collected.
The traversal now uses direct checks and skips repeated work. It keeps the same type order, lazy lookups, and errors.
Validation
Median times on CPython 3.12.13, Linux x86-64, measured on the same isolated CPU:
The gain applies to schema recreation. The other workloads show little change.
The seven tests in the serialization, schema, async iterable, and client-schema benchmark modules also pass.
Ruff lint and formatting checks pass for
srcandtests; mypy passes for all 152 source files.To reproduce the native checks and these benchmarks:
Why this is safe and easy to maintain
The change stays within one traversal method and its imports.
Existing tests cover schema type collection, wrappers, cycles, and schema errors.
The results retain the same type identities and insertion order.
Implementation details
The cast is used only during static type checks. Recursive method bindings are created only in branches that traverse references.
Empty built-in argument dictionaries skip iteration; custom mappings keep their original traversal path.
AI assistance: Codex gpt-6.1-sol generated candidates; Weco Observe recorded their results.
Weco share link: https://dashboard.weco.ai/share/9qoGWp7nl9WycSEh72uDDBGedk8a-V6N