python / python/cpython

`PyType_GetModuleByDef` is really slow.

オープン
#119,663 コメント 10 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

説明

PyType_GetModuleByDef does a lot of work for what was a single memory read prior to sub-interpreters.

For example, https://github.com/python/cpython/issues/114682.

We should provide a more efficient way to get to the module state from the module def.

AFAICT, the function to get the module state is a pure function of the interpreter and the module def.
Since the module def already has a m_index field that is described as "The module's index into its interpreter's modules_by_index cache.", then a Py_GetModuleFromDef() function could be as simple as:

inline PyObject *
Py_GetModuleFromDef(PyModuleDef *def)
{
     return PyInterpreterState_Get()->modules_table[def->m_base.m_index];
}

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

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

はじめの一歩

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

調査の方向性

PyType_GetModuleByDef、PyModuleDef.m_index、および issue で言及されているインタープリターの modules_by_index キャッシュから始めてください。現在の検索経路と提案されている module-from-definition API を比較し、報告されているオーバーヘッドに対処しながら、インタープリターごとに動作が正しいままであることを確認してください。

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

評価

技術スタック
c, python
領域
backend-api-design, performance
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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