collect_fields spends extra time on selections without directives
維護者通常 1 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 78/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
- 領域
- performance
研究方向
從 src/graphql/execution/collect_fields.py 中的 visit_selection_sets() 開始,追蹤它在有和沒有指令的選擇中對 should_include_node() 的呼叫。變更迴圈前,先檢查現有的欄位收集和指令行為測試。最佳化完成的標準是:保留結果、錯誤和禁止指令清單,同時避免不必要的指令檢查;將耗時與 issue 中的基準測試案例進行比較。
由索引模型根據 Issue 內容生成。
描述
visit_selection_sets() in src/graphql/execution/collect_fields.py runs for every selection set before resolvers run.
For each selection, it calls should_include_node(), even when the selection has no directives.
should_include_node() then builds two generator expressions to look for @skip and @include.
Most fields in real queries have no directives, so this work is repeated for almost every field.
| Situation | Now | With the proposed fix | Change |
|---|---|---|---|
collect_fields on 4,000 plain fields |
4458.7 µs | 4113.4 µs | 7.7% less time |
collect_fields on 4,000 fields with @include(if: $t) |
10988.9 µs | 8593.5 µs | 21.8% less time |
collect_fields on 40 inline fragments with 100 fields each |
4561.1 µs | 4165.7 µs | 8.7% less time |
collect_fields on 400 named fragment spreads with 1 field each |
960.0 µs | 889.9 µs | 7.3% less time |
These are medians of 31 timing rounds, and the median of 3 alternating processes per version.
Proposed fix: check selection.directives once in the loop and skip the should_include_node() call when it is empty.
Find @skip and @include in one plain loop instead of two generator expressions.
Results, errors and forbidden-directive lists stay the same.
Environment: CPython 3.12.13, Linux x86-64, AMD EPYC 9R14, graphql-core main at 1d505c1.
- 主要語言
- Python
- 星號
- 534
- 分支
- 159
- 平均合併
- 1 天 18 小時
- 30 天內合併 PR
- 9
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
graphql-python/graphql-core 的其他 Issue
-
is_printable_as_block_string checks each character in a Python loop可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 83/100
graphql-python/graphql-core#312 ·
維護者通常 1 天內回覆
-
natural_comparison_key: faster sort keys for names without digits可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
graphql-python/graphql-core#310 ·
維護者通常 1 天內回覆
-
Make is_awaitable faster for values that are not awaitable可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
graphql-python/graphql-core#308 ·
維護者通常 1 天內回覆
-
assert_name checks each character in a Python generator可能已有人在做 @swayamdudhela 於 2 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
graphql-python/graphql-core#304 · 4 則留言 ·
維護者通常 1 天內回覆
-
coerce_input_literal spends extra time on type checks and non-null recursion可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
graphql-python/graphql-core#302 ·
維護者通常 1 天內回覆
查看 graphql-python/graphql-core 的全部 Issue
相似的 Issue
-
cli good first issue help wanted python up-for-grabs
難度 2/5 1-3 小時 新手友好度 75/100
andrewsiah/agentswarm-data-tasks#36 ·
維護者通常 1 天內回覆
-
bug drawing-tools
難度 2/5 1-3 小時 新手友好度 76/100
cofade/open-garden-planner#827 ·
維護者通常 1 天內回覆
-
Methodology page未關閉documentation site texts
難度 2/5 1-3 小時 新手友好度 67/100
Krasnopjorovs/temet#66 ·
-
bug
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆
-
難度 1/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆