assert_name checks each character in a Python generator
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- backend-api-design, performance
Research direction
Start with src/graphql/type/assert_name.py and read assert_name() alongside the existing name validation tests. Check the proposed isascii() and isidentifier() fast path against the specified GraphQL name pattern, while preserving current errors for invalid names. Run the relevant tests and compare schema build timings; done means valid names take the fast path and invalid names retain their existing behavior.
Written by the indexing model from the issue text.
Description
assert_name() in src/graphql/type/assert_name.py runs for every type, field, argument and enum value name when a schema is built.
It checks the name tail with all(is_name_continue(char) for char in name[1:]).
This runs one Python function call for each character.
For a schema of the GitHub size, this check uses about one quarter of the build time.
| Situation | Now | With the proposed fix | Change |
|---|---|---|---|
build_ast_schema on the GitHub SDL (assume_valid=True) |
14.40 ms | 10.79 ms | 25.0% less time |
build_client_schema on the GitHub introspection result |
13.97 ms | 10.43 ms | 25.3% less time |
assert_name on 10,000 valid names |
6.94 ms | 0.69 ms | 90.0% less time |
assert_name on 10,000 invalid names |
13.32 ms | 8.62 ms | 35.3% less time |
parse on the large query (does not call assert_name) |
38.43 ms | 37.90 ms | No change (within noise) |
These are the best of 15 runs, median of 7 alternating processes per version.
Proposed fix: for an ASCII string, str.isidentifier() is true exactly for [_a-zA-Z][_a-zA-Z0-9]*.
Use name.isascii() and name.isidentifier() to return valid names early, and keep the current error checks and messages for invalid names.
Environment: CPython 3.12.13, Linux x86-64, AMD EPYC 9R14, graphql-core main at 0aaea71.
- Dominant language
- Python
- Stars
- 534
- Forks
- 159
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 11
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/graphql-core
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
graphql-python/graphql-core#302 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
graphql-python/graphql-core#278 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
graphql-python/graphql-core#257 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
graphql-python/graphql-core#223 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
graphql-python/graphql-core#220 · 4 comments ·
Maintainers usually reply within 1 day
All issues in graphql-python/graphql-core
Similar issues
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
docs size:S
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Gathin23/cleanyourtv#3464 ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
strawberry-graphql/strawberry#4794 ·
Maintainers usually reply within 1 day