graphql-python / graphql-python/graphql-core
Performance issues related to complete_value on large datasets
- 主要語言
- Python
- 星號
- 531
- 分支
- 146
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Hi! We've noticed that returning a list of 5k elements, with a couple of nested objects is pretty slow:
```
Person {
id
name
lastname
age
address {street number}
job {id org_name}
partner {id name}
pets {name type}
school {id name}
}
```

ncalls | tottime | percall | cumtime | percall | filename:lineno(function)
-- | -- | -- | -- | -- | --
1 | 1.8e-05 | 1.8e-05 | 2.145 | 2.145 | graphql.py:103(graphql_sync)
1 | 1.5e-05 | 1.5e-05 | 2.145 | 2.145 | graphql.py:152(graphql_impl)
1/30001 | 0.19 | 6.335e-06 | 2.137 | 7.122e-05 | execute.py:413(ExecutionContext.execute_fields)
1 | 1.3e-05 | 1.3e-05 | 2.137 | 2.137 | execute.py:965(execute)
1 | 7e-06 | 7e-06 | 2.137 | 2.137 | execute.py:328(ExecutionContext.execute_operation)
1/135001 | 0.3229 | 2.392e-06 | 2.135 | 1.581e-05 | execute.py:485(ExecutionContext.execute_field)
1/145001 | 0.2737 | 1.888e-06 | 2.071 | 1.428e-05 | execute.py:575(ExecutionContext.complete_value)
1 | 0.009884 | 0.009884 | 2.071 | 2.071 | execute.py:660(ExecutionContext.complete_list_value)
**5000/30000** | 0.02747 | 9.156e-07 | 2.026 | 6.752e-05 | execute.py:893(ExecutionContext.complete_object_value)
By itself it's not really a slow function, but its executed 30k times. Is there any way to reduce the overhead by reducing the number of times this function is invoked?
Tested on Python 3.8 and graphql-core==3.2.3
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
從 execute.py 中的 ExecutionContext.complete_value、complete_list_value 和 complete_object_value 開始,以回報的 graphql.py 呼叫路徑作為重現入口。在 Python 3.8 和 graphql-core 3.2.3 上重現包含 5,000 個元素的巢狀查詢,對執行過程進行效能分析,並驗證任何變更都會在不改變回傳結果的情況下降低額外負擔。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- api, performance
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 35/100