Avoid unnecessary NotShareableError creation in XIData FULL_FALLBACK
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Proposal:
Motivation
The pickle fallback path in _PyObject_GetXIData() does unnecessary work on successful transfers of types that are not in the XIData registry, creating and discarding a NotShareableError that user code never sees.
This is a follow-up to gh-148072 / GH-148125, which cached pickle.dumps and pickle.loads per interpreter. That change removed module lookup overhead, but there is still avoidable cost in the fallback path itself.
This extra exception work adds measurable overhead to cross-interpreter transfers that rely on pickle fallback.
Approach
Check the XIData registry first with lookup_getdata() before calling _get_xidata().
- If the type is registered, keep using the existing path unchanged.
- If the type is not registered, skip
_get_xidata()and go directly to the function/pickle fallback chain.
On total failure, raise the same NotShareableError as the existing code path, so external behavior stays the same.
Benchmark results
This removes unnecessary exception creation on a hot fallback path and gives a measurable speedup for transfers that rely on pickle fallback.
In local benchmarks on Apple M2, combined with GH-148125, this improved round-trip transfer times for mutable objects such as list and dict, especially for larger payloads.
Large-payload benchmark results (500 iterations, Apple M2)
Baseline is upstream/main after GH-148125 (pickle cache). "After" includes this change.
| Data | Before | After | Speedup |
|---|---|---|---|
list [1 x 100KB] |
1.19ms | 0.12ms | 9.9x |
list [1 x 1MB] |
10.26ms | 0.20ms | 51x |
list [10 x 100KB] |
9.99ms | 0.10ms | 100x |
dict {10 x 100KB} |
10.41ms | 0.26ms | 40x |
Related
- gh-148072 — Predecessor: pickle module caching (merged as GH-148125)
- gh-124694 — InterpreterPoolExecutor addition
Validation
Local testing passed:
./python -m test test_interpreters./python -m test test_concurrent_futures
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:
Linked PRs
- gh-148224
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
_PyObject_GetXIData() から始め、pickle のフォールバックパスにある lookup_getdata() と _get_xidata() を追跡します。リンクされている PR gh-148224 を確認してから、./python -m test test_interpreters と ./python -m test test_concurrent_futures を実行します。既存の NotShareableError の動作を維持しつつ、不要な例外の生成を避けられれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend, performance
- issue の種類
- リファクタリング
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100