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 <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Heikki Toivonen 2026-01-08 07:28:02 -08:00 committed by GitHub
parent 8cf5c4d89a
commit cea2d2475d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 1 deletions

View File

@ -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

View File

@ -1931,6 +1931,7 @@ James Tocknell
Bennett Todd
R Lindsay Todd
Eugene Toder
Heikki Toivonen
Erik Tollerud
Stephen Tonkin
Matias Torchinsky

View File

@ -0,0 +1 @@
Speed up :func:`copy.deepcopy` by 1.04x.