python / python/cpython

Improve performance by using reference stealing methods

オープン
#150,942 コメント 19 件 リアクション 8 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

easy extension-modules performance type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Modules/_csv.c、Modules/pyexpat.c、Modules/_elementtree.c、および _io、Objects、_pickle、_asynciomodule のファイルを含む、一覧にある C の箇所を確認してください。まずリンクされている PR を確認し、どのケースがすでにカバーされているかを確認してください。残りの作業は、関連するパフォーマンステストを含む、個別のスコープを限定した issue に分割してください。完了の条件は、選択したパフォーマンスクリティカルなケースを複雑さを増やさずに変更し、その動作とパフォーマンスを検証することです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, python
領域
backend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。