Skip to content

perf(print_schema): print descriptions without the AST printer - faster print_schema - #324

Merged
Cito merged 2 commits into
graphql-python:mainfrom
g4lb:perf-print-description
Nov 17, 2026
Merged

Cito merged 2 commits into
graphql-python:mainfrom
g4lb:perf-print-description

Conversation

@g4lb

@g4lb g4lb commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

print_description() now gives the description to print_block_string() or print_string() directly. Before, it made a StringValueNode and called print_ast(), which runs the AST printer for one node. The output does not change.

Benchmark (CPython 3.14) Before After Change
print_schema of the GitHub schema 8.98 ms 5.38 ms -40%

Time ratios (new/old) for print_schema of the GitHub schema: 0.60 on CPython 3.10, 0.62 on 3.14, 0.63 on 3.15, and 0.90-1.04 on PyPy 3.11 (4 runs).

I measured no slowdown on schemas with no descriptions, short descriptions, control characters, long and multi-line descriptions, a schema from introspection, and print_introspection_schema. I used 150-400 interleaved rounds (Apple M5). Import time did not change (30 rounds). I did not measure other architectures.

Checks:

  • tox -e py310,py311,py312,py313,py314,py315,pypy311,ruff,mypy,docs passes.
  • Old and new outputs matched on 1,000,000 random descriptions (CPython 3.14 and PyPy 3.11).

@g4lb
g4lb requested a review from Cito as a code owner November 17, 2026 20:43
@codspeed

codspeed Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing g4lb:perf-print-description (ba88d70) with main (9d99a99)

Open in CodSpeed

@Cito

Cito commented Nov 17, 2026

Copy link
Copy Markdown
Member

Thanks! I pushed a small follow-up: a conditional expression, plus a note to keep this in sync with print_string_value in the printer.

@Cito
Cito merged commit c4118eb into graphql-python:main Nov 17, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants