Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Optimize deepcopy for 1.04x speedup
Gains according to pyperformance:
```
deepcopy:
Mean +- std dev: 411 us +- 2 us -> 396 us +- 3 us: 1.04x faster
Significant (t=28.94)

deepcopy_reduce:
Mean +- std dev: 4.38 us +- 0.05 us -> 4.23 us +- 0.04 us: 1.04x faster
Significant (t=20.05)
```
  • Loading branch information
heikkitoivonen committed Jan 5, 2026
commit 35c3168b82f87cb55a7165f6e7ecc50152d05b67
2 changes: 1 addition & 1 deletion Lib/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _reconstruct(x, memo, func, args,
*, deepcopy=deepcopy):
deep = memo is not None
if deep and args:
args = (deepcopy(arg, memo) for arg in args)
args = [deepcopy(arg, memo) for arg in args]
y = func(*args)
if deep:
memo[id(x)] = y
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,7 @@ James Tocknell
Bennett Todd
R Lindsay Todd
Eugene Toder
Heikki Toivonen
Erik Tollerud
Stephen Tonkin
Matias Torchinsky
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optimize deepcopy in :mod:`copy`, pyperformance reports 1.04x speedup.
Comment thread
heikkitoivonen marked this conversation as resolved.
Outdated
Loading