Use tagged ints for faster iteration
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Iteration over tuples and short lists is quite inefficient as we need to create an iterator object, only to have to destroy it again moments later. Not only that, fetching values from iterators involves additional indirection compared to fetching them from sequences.
Instead we can push a pair of values to the stack. For common sequences, like tuple, list, strings, some ranges and a few others, we push the sequence and the integer index (initially 0) to the stack. For other iterables, we push the iterator and NULL.
GET_ITER will have the signature:
iterable -- iter, index_or_null
FOR_ITER now has the signature:
iter, index_or_null -- iter, index_or_null, next.
What makes this efficient is tagged integers. By using tagged integers, no objects need to be created.
Examples
GET_ITER
[ <tuple at ...> ] -> [ <tuple at ...>, 0 ]
[ <file at ...> ] -> [ <file iterator at ...>, NULL ]
FOR_ITER
[ <tuple at ...>, 0 ] -> [ <tuple at ...>, 1, item0 ]
[ <file iterator at ...>, NULL ] -> [ <file iterator at ...>, NULL, line ]
Linked PRs
- gh-132555
- gh-132592
- gh-135063
- gh-135137
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている PR gh-132555、gh-132592、gh-135063、gh-135137 から始めて現在の実装状況を確認し、続いてここで説明されている GET_ITER と FOR_ITER のスタックシグネチャを追跡します。完了とは、一般的なシーケンスがイテレータオブジェクトなしでタグ付き整数インデックスを使用し、それ以外の iterable はイテレータと NULL を保持することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers, performance
- issue の種類
- リファクタリング
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100