python / python/cpython

Avoid unnecessary NotShareableError creation in XIData FULL_FALLBACK

未关闭
#148,223 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core type-feature
主要语言
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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

_PyObject_GetXIData() 开始,跟踪 pickle fallback 路径中的 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

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。