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時間
- マージ済み PR(30日)
- 9
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
graphql-python/graphql-core のほかの issue
-
collect_fields spends extra time on selections without directives対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
graphql-python/graphql-core#315 ·
メンテナーはふだん 1 日以内に返信
-
is_printable_as_block_string checks each character in a Python loop対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
graphql-python/graphql-core#312 ·
メンテナーはふだん 1 日以内に返信
-
Make is_awaitable faster for values that are not awaitable対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 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対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 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 日以内に返信
-
hardware help wanted testing
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
難易度 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 日以内に返信