Improve performance of exception raise
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- python
- 領域
- backend, performance
調査の方向性
The issue identifies _PyErr_SetObject() and _PyErr_SetRaisedException() as the relevant entry points; start by reading their implementations and the linked PR gh-160476. Compare the exception raising benchmarks described in the issue, including the free-threaded cases, and check whether the proposed direct call preserves the existing behavior. The linked PR indicates work is already underway.
索引モデルが issue の本文から書いたものです。
説明
Feature or enhancement
At the end of _PyErr_SetObject() the value is a normalized BaseException instance. The function still took a new reference to Py_TYPE(value) and fetched the value's traceback, only for _PyErr_Restore() to set that traceback back on the same object, store the value and drop the type again. Instead we can call _PyErr_SetRaisedException() directly.
Benchmarks
Default build, single thread:
| Benchmark | base | patch |
|---|---|---|
raise E / except E (heap type) |
174 ns | 171 ns: 1.02x faster |
raise E('message') / except E |
210 ns | 205 ns: 1.02x faster |
raise KeyError(1) / except KeyError (static type) |
192 ns | 176 ns: 1.09x faster |
d[1] / except KeyError (raised from C) |
177 ns | 170 ns: 1.04x faster |
f() / except E (raise through a frame) |
290 ns | 284 ns: 1.02x faster |
| Geometric mean | (ref) | 1.04x faster |
The gain is within binary layout noise range, but in the right direction.
Free-threaded build, N threads each running try: raise E / except E: pass with E defined
by the main thread:
| case | 1 thr | 2 thr | 4 thr | 8 thr |
|---|---|---|---|---|
ctl: isinstance(b, A) |
1.00 | 1.00 | 1.00 | 1.00 |
raise E / except E |
1.03-1.04 | 1.12-1.15 | 1.34-1.44 | 1.60-1.70 |
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
- gh-160476
- 主要言語
- Python
- スター
- 77.8k
- フォーク
- 37.7k
- 平均マージ
- 15時間 24分
- マージ済み PR(30日)
- 728
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
What's New in 3.12 credits the unstable C API tier to PEP 697 instead of PEP 689対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンdocs
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
python/cpython#161078 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
OS-windows type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
docs
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
python/cpython#161007 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Null dereferencing of a pointer in initconfig.c対応中かも @lazerg が 3 日前に担当しました。 オープンinterpreter-core topic-C-API type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
python/cpython#160962 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
tests topic-profiling type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
python/cpython#160881 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
URLValidator ignores an explicit empty scheme allowlist対応中かも @IlyaKhalafi が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
tortoise/tortoise-orm#2393 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
frappe/frappe_docker#2046 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
complete_box_iou_loss / complete_box_iou: NaN gradients for zero-height boxes, NaN for point boxesオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
AXI SMU SPEC
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
tenstorrent/tt-oca-harness#3556 ·
メンテナーはふだん 1 日以内に返信