natural_comparison_key: faster sort keys for names without digits
維護者通常 1 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 76/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
- 領域
- performance
研究方向
從 src/graphql/pyutils/natural_compare.py 中的 natural_comparison_key 開始,並閱讀 tests/pyutils/test_natural_compare.py。檢查提議的快速路徑和切片指定是否保留現有鍵,然後執行指定的測試檔案。測試通過且最佳化維持鍵不變,即表示完成。
由索引模型根據 Issue 內容生成。
描述
natural_comparison_key in src/graphql/pyutils/natural_compare.py runs for every name when lexicographic_sort_schema sorts a schema. It is also used by suggestion_list and sort_value_node.
Problem
The function always splits the name with a regex. Then it walks the parts with zip and itertools.cycle inside a generator. Most GraphQL names (userName, createdAt) have no digits. For these names, this work always gives the same one-item tuple (name,).
Numbers
I measured the current code and a small change with timeit (CPython 3.12, Linux). The table shows the time to compute the keys for each list of names.
| Situation | Current | Proposed | Change |
|---|---|---|---|
| GitHub schema names (3323 names) | 2.11 ms | 0.34 ms | 84% faster |
Letters only, userName (5000 names) |
3.00 ms | 0.38 ms | 88% faster |
Underscore names, USER_NAME (5000 names) |
3.09 ms | 1.83 ms | 41% faster |
Names with numbers, field12x3 (5000 names) |
5.61 ms | 3.72 ms | 34% faster |
Proposed fix
Return (key,) early when key.isalpha() is true, because such a name cannot contain a decimal digit. For other names, keep the regex split and replace the digit parts in one slice assignment instead of the zip/cycle generator. The keys stay exactly the same, and the existing tests in tests/pyutils/test_natural_compare.py pass.
Environment
- graphql-core
mainat 1d505c1 - CPython 3.12, Linux x86_64
- 主要語言
- Python
- 星號
- 534
- 分支
- 159
- 平均合併
- 1 天 18 小時
- 30 天內合併 PR
- 9
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
graphql-python/graphql-core 的其他 Issue
-
collect_fields spends extra time on selections without directives可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
graphql-python/graphql-core#315 ·
維護者通常 1 天內回覆
-
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 天內回覆
-
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
-
`destroy` sans terminal répond « Aborted. » au lieu de réclamer `--yes` comme `clean` et `reset`未關閉bug
難度 2/5 1-3 小時 新手友好度 85/100
stephrobert/dsoxlab#354 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 77/100
jasonacox/pypowerwall#472 ·
維護者通常 1 天內回覆
-
[Bug]: DoubleMLRDDData accepts a score_col that is no data column (as in its docstring example); the running variable then becomes a covariate and RDFlex fails可能已有人在做 @vrjdev 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
DoubleML/doubleml-for-py#455 ·
維護者通常 1 天內回覆
-
[Bug]: Python mod.Box[T] annotation gets a false generic_arg edge that replaces the parameter_type one ('is' on tree-sitter nodes)可能已有人在做 @rohit-jsfreaky 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 88/100
Graphify-Labs/graphify#5110 · 1 則留言 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
assafelovic/gpt-researcher#2277 ·
維護者通常 10 天內回覆