assert_name checks each character in a Python generator

未关闭 适合新手
#304 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

从 src/graphql/type/assert_name.py 开始,结合现有的名称验证测试阅读 assert_name()。根据指定的 GraphQL 名称模式检查提议的 isascii() 和 isidentifier() 快速路径,同时保留无效名称当前产生的错误。运行相关测试并比较 schema 构建耗时;完成标准是有效名称走快速路径,无效名称保持现有行为。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
534
派生
159
平均合并
1 天 10 小时
30 天内合并 PR
11

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

graphql-python/graphql-core 的其他 Issue

查看 graphql-python/graphql-core 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。