python / python/cpython

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

Aperta
#150,815 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

performance stdlib type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal punto di ingresso copy.deepcopy() ed esamina la PR collegata gh-150822, che indica che il lavoro è già in corso. Verifica che l’ottimizzazione segnalata preservi i riferimenti condivisi, le strutture ricorsive e la gestione delle sottoclassi di int/tuple, ottenendo al contempo il miglioramento del benchmark indicato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
performance
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.