python / python/cpython

Improved performance and arguably simpler code for dictionaries by changing the keys layout

オープン
#142,889 コメント 1 件 リアクション 3 件 担当者 0 名 GitHub で見る

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

interpreter-core performance type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Current layout

Currently the _dictkeysobject struct is laid out like this:

ptr ---->  +--------------+
           |     header   |
           +--------------+
           |    indices   |
           +--------------+
           |     keys     |
           +--------------+

which requires some relatively expensive calculation to find the start of the keys, as the indices are not only variable in number, but variable in size also.

Proposed layout

If instead it is laid out as follows:

           +--------------+
           |    indices   |
ptr ---->  +--------------+
           |     header   |
           +--------------+
           |     keys     |
           +--------------+

and the indices laid from highest to lowest with 0 just before ptr, finding the start of the keys is as simple as ptr->keys . Accessing an index is no slower, and the code barely any more complex.

Linked PRs
  • gh-145097
  • gh-150640

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

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

はじめの一歩

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

調査の方向性

作業がそちらに移っているため、まず提案されている _dictkeysobject のレイアウトと、リンクされている PR gh-145097 および gh-150640 を確認してください。現在の index、header、keys の配置と提案された配置を比較してください。完了するには、新しいレイアウトをサポートする実装と、その性能または正しさの検証が必要です。

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

評価

技術スタック
python
領域
backend
issue の種類
リファクタリング
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

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

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