Description
Rebuilding a large schema repeatedly calls type-check helpers for references already collected.
The repository's GitHub schema recreation benchmark takes 1.310 ms per call in my measurements.
A small change to TypeSet.collect_referenced_types uses direct class checks and skips repeated work.
It preserves type order, lazy lookups, and errors.
| Situation | Before | With proposed change | Change |
|---|---|---|---|
| Recreate the GitHub schema | 1.310 ms | 0.903 ms | 31.0% less time |
| Build a schema from introspection | 14.959 ms | 14.713 ms | 1.6% less time |
| Execute an async iterable list field | 1.212 ms | 1.199 ms | 1.1% less time |
| Decode a pickled large-query AST | 6.955 ms | 6.957 ms | No measurable change |
These are median times on the same isolated CPU, using CPython 3.12.13 and Linux x86-64.
The source is graphql-core 3.3.1 at commit 0aaea717d8a6ca4e7241fb798ff4f0216dde61ee.
Reproduction:
PYTHONPATH=src python -m pytest tests/benchmarks/test_graphql_schema.py \
tests/benchmarks/test_build_client_schema.py \
tests/benchmarks/test_async_iterable.py \
tests/benchmarks/test_serialization.py --benchmark-enableThe native suite passes with the change: 3,625 passed and 18 skipped.
AI assistance: Codex gpt-6.1-sol generated the candidate, and Weco Observe recorded its measurements.
I have a tested patch ready and would be glad to open a pull request if this approach fits the project.
Activity
Cito commentedon Nov 6, 2026
Done in #301, part of 3.3.2.
[-]# Reduce repeated type checks during schema reconstruction[/-][+]Reduce repeated type checks during schema reconstruction[/+]