coerce_input_literal spends extra time on type checks and non-null recursion
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 重构
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
- 领域
- performance
调研方向
阅读 src/graphql/utilities/coerce_input_value.py 和 tests/benchmarks/test_execution_arguments.py 中的基准测试。检查 coerce_input_literal 如何处理 NonNull 类型并调用三个类型检查辅助函数,然后进行建议的更改并运行相关测试和基准测试。行为保持不变且基准测试显示报告中的性能提升时,即为完成。
由索引模型根据 Issue 内容生成。
描述
coerce_input_literal in src/graphql/utilities/coerce_input_value.py runs for every literal argument in a query. For example, it runs for multiplier: 2 once per item in tests/benchmarks/test_execution_arguments.py.
The function does two kinds of extra work:
- For a
NonNulltype, it calls itself again with the inner type. The second call checks for a variable node and a non-null type again. - It uses the
is_non_null_type,is_list_typeandis_input_object_typehelper functions. Each helper is one more function call around anisinstancecheck.
Measured on Python 3.12, median of 3 runs (time per call):
| Situation | Now | With direct checks | Change |
|---|---|---|---|
Int! literal (multiplier: 2) |
734 ns | 479 ns | 35% faster |
[Int!] list of 10 ints |
7557 ns | 5089 ns | 33% faster |
input object {a: 1, b: "x"} |
2355 ns | 1717 ns | 27% faster |
variable $v |
172 ns | 156 ns | no real change |
execute_sync of the 1000-item benchmark query |
5.32 ms | 5.00 ms | 6% faster |
Proposed fix: unwrap the NonNull type in place instead of calling the function again. Use direct isinstance checks against GraphQLNonNull, GraphQLList and GraphQLInputObjectType in this one function. The results stay the same, and the full test suite passes with the change.
Environment: graphql-core main at 0aaea71, CPython 3.12.13, Linux x86_64.
- 主要语言
- Python
- 星标
- 534
- 派生
- 159
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 11
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
graphql-python/graphql-core 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
graphql-python/graphql-core#304 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 35/100
graphql-python/graphql-core#278 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 45/100
graphql-python/graphql-core#257 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 35/100
graphql-python/graphql-core#223 · 1 条评论 ·
维护者通常 1 天内回复
-
documentation good first issue
难度 2/5 1-3 小时 新手友好度 35/100
graphql-python/graphql-core#220 · 4 条评论 ·
维护者通常 1 天内回复
查看 graphql-python/graphql-core 的全部 Issue
相似的 Issue
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 78/100
-
docs size:S
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 88/100
Gathin23/cleanyourtv#3464 ·
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
strawberry-graphql/strawberry#4794 ·
维护者通常 1 天内回复