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 天內回覆