python / python/cpython

Speed up copy.deepcopy() of containers holding atomic elements

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

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

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

説明

copy.deepcopy() copies a structure by sending every element back through deepcopy(). For elements that need no copying at all — strings, ints, None, booleans, floats and the other immutable atomic types — that round trip still costs a function call each, even though the value handed back is the same object.

Real data is dominated by these atomic leaves. A parsed JSON document, a settings dict cloned before mutation, a record copied inside a framework: the keys are strings and most values are strings and numbers. Copying such a structure spends most of its time calling deepcopy() only to receive the same object straight back.

Deep-copying 105 JSON documents drawn from the top-1000 PyPI projects takes 1.20 ms today. Folding the atomic-type check into the dict, list and tuple copiers brings that to 970 µs, 23% faster, with identical handling of shared references, recursive structures and int/tuple subclasses.

Linked PRs
  • gh-150822

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

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

はじめの一歩

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

調査の方向性

copy.deepcopy() のエントリポイントから開始し、リンクされている PR gh-150822 を調査してください。これは、すでに作業が進行中であることを示しています。報告されている最適化が共有参照、再帰的な構造、int/tuple のサブクラスの扱いを維持し、提示されたベンチマーク改善と一致することを検証してください。

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

評価

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

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

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