Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Optimize copy.deepcopy by converting a generator expression into list comprehension - 1.04x improvement in pyperformance #143445

Closed
Labels
performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
@heikkitoivonen

Description

@heikkitoivonen

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

No one assigned

    Labels

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp