Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
Closed
Description
Feature or enhancement
Proposal:
There is a generator expression that is created forcopy.deepcopy and immediately fully consumed with all the values needed simultaneously, so the generator provides no value. Converting this to list comprehension makes the code faster. pyperformance shows 1.04x improvement.
ifdeepandargs:-args= (deepcopy(arg,memo)forarginargs)+args= [deepcopy(arg,memo)forarginargs]y=func(*args)
pyperformance comparison:
deepcopy_baseline.json======================Performance version: 1.13.0Python version: 3.15.0a3+ (64-bit) revision 4f9a8d075eeReport on macOS-14.6.1-arm64-arm-64bit-Mach-ONumber of logical CPUs: 8Start date: 2026-01-05 10:59:45.355502End date: 2026-01-05 11:15:48.467921deepcopy_optimized.json=======================Performance version: 1.13.0Python version: 3.15.0a3+ (64-bit) revision 4f9a8d075eeReport on macOS-14.6.1-arm64-arm-64bit-Mach-ONumber of logical CPUs: 8Start date: 2026-01-05 11:26:34.289860End date: 2026-01-05 11:42:13.727498### deepcopy ###Mean +- std dev: 411 us +- 2 us -> 396 us +- 3 us: 1.04x fasterSignificant (t=28.94)### deepcopy_memo ###Mean +- std dev: 49.7 us +- 0.4 us -> 49.7 us +- 0.4 us: 1.00x fasterNot significant### deepcopy_reduce ###Mean +- std dev: 4.38 us +- 0.05 us -> 4.23 us +- 0.04 us: 1.04x fasterSignificant (t=20.05)I will make a PR for this.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done