https://github.com/python/cpython/commit/cea2d2475d3eec9f4fd350ef9eb2ba43da1943a5
commit: cea2d2475d3eec9f4fd350ef9eb2ba43da1943a5
branch: main
author: Heikki Toivonen <[email protected]>
committer: vstinner <[email protected]>
date: 2026-01-08T16:28:02+01:00
summary:

gh-143445: Optimize deepcopy for 1.04x speedup (#143449)

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)
```

Co-authored-by: Bénédikt Tran <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-01-05-12-20-42.gh-issue-143445.rgxnbL.rst
M Lib/copy.py
M Misc/ACKS

diff --git a/Lib/copy.py b/Lib/copy.py
index fff7e93c2a1b89..4c024ab5311d2d 100644
--- a/Lib/copy.py
+++ b/Lib/copy.py
@@ -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
diff --git a/Misc/ACKS b/Misc/ACKS
index 671fcf88c75af9..63ddfb89071c0b 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1931,6 +1931,7 @@ James Tocknell
 Bennett Todd
 R Lindsay Todd
 Eugene Toder
+Heikki Toivonen
 Erik Tollerud
 Stephen Tonkin
 Matias Torchinsky
diff --git 
a/Misc/NEWS.d/next/Library/2026-01-05-12-20-42.gh-issue-143445.rgxnbL.rst 
b/Misc/NEWS.d/next/Library/2026-01-05-12-20-42.gh-issue-143445.rgxnbL.rst
new file mode 100644
index 00000000000000..f5dea2e49afe2a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-01-05-12-20-42.gh-issue-143445.rgxnbL.rst
@@ -0,0 +1 @@
+Speed up :func:`copy.deepcopy` by 1.04x.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to