python / python/cpython

Speed up inspect.signature() for Python functions

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

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

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

説明

inspect.signature() builds a Signature whose every Parameter is constructed through the public Parameter constructor, which validates the name and kind on each call. When the parameters come from a function's own code object the names are already valid identifiers and the kinds are already the canonical constants, so that validation re-checks facts that are guaranteed to hold.

Signature introspection runs constantly in the ecosystem: web frameworks resolving view and dependency arguments, CLI libraries like click, pytest fixture wiring, and serialization and validation layers all call it per function, often at import time while wiring an application together.

Taking the signature of 400 real callables collected from popular packages (requests, click, jinja2, sqlalchemy, werkzeug, flask and others) takes 1.46 ms today and 1.16 ms when trusted-source parameters skip the redundant validation, 26% faster, with the public Parameter() constructor and its validation unchanged for every other caller.

Linked PRs
  • gh-150823
  • gh-157463

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

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

はじめの一歩

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

調査の方向性

まず、inspect.signature() を Signature と公開 Parameter コンストラクターを通して追跡し、関数のコードオブジェクトから取得されるパラメーターに注目します。既存のパスおよび Trusted-Source パスを、issue で説明されている 400-callable ベンチマークと比較し、公開された Parameter() の検証が変更されないまま、報告されたパフォーマンス改善が再現されることを確認します。

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

評価

技術スタック
python
領域
developer-experience
issue の種類
リファクタリング
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

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

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