is_printable_as_block_string checks each character in a Python loop
維護者通常 1 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 83/100
- Issue 類型
- 重構
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
- 領域
- performance
研究方向
閱讀 is_printable_as_block_string() 及其在 GraphQL.js 中對應的四項檢查,接著檢視 tests/language/test_block_string.py,了解現有行為的測試涵蓋情況。將字元迴圈替換為所述的字串方法檢查,同時保留所有輸入的結果。執行該測試檔並比較測量的案例;當行為維持不變,且長描述案例顯示出所回報的速度提升時,即為完成。
由索引模型根據 Issue 內容生成。
描述
print_schema() and print_ast() call is_printable_as_block_string() once for each description. The function walks the string one character at a time in a Python for loop. It keeps four boolean flags for each character. For long descriptions, this loop is a large part of the time that print_schema() uses.
Measured with Python 3.12 on one isolated CPU core (best of 7 runs):
| Situation | Now | With str methods | Change |
|---|---|---|---|
| One-line description (30 chars) | 1405 ns | 184 ns | 87% less time |
| Description with 12 lines | 19.2 µs | 2.7 µs | 86% less time |
print_schema() of the GitHub schema fixture |
25.5 ms | 16.3 ms | 36% less time |
| String that starts with a new line | 106 ns | 427 ns | 0.3 µs slower |
The last row is the only slower case. The old loop stops at the first character there. Such strings are rare in real schemas.
Proposed fix: keep the same checks, but use str methods instead of the character loop. A str.isprintable() pre-check and a regex find control characters. Then str.split("\n") gives the lines for the leading, trailing and indent checks. The result stays the same for all inputs, and tests/language/test_block_string.py passes.
This is a Python-specific change only. It keeps the four rules of isPrintableAsBlockString in GraphQL.js as four short checks with the same comments, so a later sync with upstream stays easy.
Environment: graphql-core main (1d505c1), CPython 3.12.13, 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 天內回覆
-
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
-
`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 天內回覆