Improve performance by using reference stealing methods
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Feature or enhancement
Proposal:
We can improve performance of cpython by using stealing methods (_PyList_AppendTakeRef, _PyDict_SetItem_Take2, PyTuple_FromPairSteal etc.) instead of the normal ones. Using stealing methods we typically avoid an incref/decref pair and sometimes error handling is simplified. We should only make changes where it makes a performance impact, the code is not more complex and the modules or methods affected are performance critical.
A list of possible cases (there might be more).
| Location | Module / context | Helper |
|---|---|---|
Modules/_csv.c:688 |
csv reader, per field | _PyList_AppendTakeRef |
Modules/pyexpat.c:472 |
pyexpat StartElement, per attribute | _PyDict_SetItem_Take2 |
Modules/_elementtree.c:3351 |
ElementTree C accel attrib dict | _PyDict_SetItem_Take2 |
Modules/_io/bytesio.c:577 |
io.BytesIO.readlines | _PyList_AppendTakeRef |
Modules/_io/iobase.c:756 |
io.IOBase.readlines (generic) | _PyList_AppendTakeRef |
Objects/frameobject.c:639 & 658 |
frame f_locals / vars() / tracing |
_PyList_AppendTakeRef |
Modules/_pickle.c:5138 |
pickle Pickler memo copy | _PyDict_SetItem_Take2 |
Modules/_io/textio.c:2337 & 2343 |
io.TextIOWrapper readline (multi-chunk) | _PyList_AppendTakeRef |
Modules/_asynciomodule.c:1213 |
asyncio future done-callback compaction | _PyList_AppendTakeRef |
Update: Most cases already have an open PR, for new ones please open a separate issue.
Linked PRs
- gh-150943
- gh-150945
- gh-150995
- gh-151002
- gh-151062
- gh-151209
- gh-151608
- gh-153013
- gh-154860
- gh-155171
- gh-155304
- gh-155922
- gh-155940
- gh-155957
- gh-156055
- gh-156199
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
檢查列出的 C 位置,包括 Modules/_csv.c、Modules/pyexpat.c、Modules/_elementtree.c,以及 _io、Objects、_pickle 和 _asynciomodule 中的檔案。首先檢查已連結的 PR,確認哪些情況已經涵蓋;任何剩餘工作都應拆分為一個獨立且範圍明確的 issue,並包含相關的效能測試。完成的標準是:在不增加複雜度的情況下修改一個選定的效能關鍵情況,並驗證其行為和效能。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c, python
- 領域
- backend
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 25/100