GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Speed up copy.deepcopy() of containers holding atomic elements · Issue #150815 · python/cpython

Speed up copy.deepcopy() of containers holding atomic elements #150815

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Speed up copy.deepcopy() of containers holding atomic elements#150815
Copy link
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@gaborbernat
gaborbernat
opened on Jun 2, 2026
Issue body actions

copy.deepcopy() copies a structure by sending every element back through deepcopy(). For elements that need no copying at all — strings, ints, None, booleans, floats and the other immutable atomic types — that round trip still costs a function call each, even though the value handed back is the same object.

Real data is dominated by these atomic leaves. A parsed JSON document, a settings dict cloned before mutation, a record copied inside a framework: the keys are strings and most values are strings and numbers. Copying such a structure spends most of its time calling deepcopy() only to receive the same object straight back.

Deep-copying 105 JSON documents drawn from the top-1000 PyPI projects takes 1.20 ms today. Folding the atomic-type check into the dict, list and tuple copiers brings that to 970 µs, 23% faster, with identical handling of shared references, recursive structures and int/tuple subclasses.

Linked PRs

  • gh-150815: Speed up copy.deepcopy() of containers with atomic elements #150822

Activity

  1. gaborbernat
    added 2 commits that reference this issue on Jun 2, 2026

    pythongh-150815: Speed up copy.deepcopy() of containers with atomic e…

    aeab6f7

    pythongh-150815: Speed up copy.deepcopy() of containers with atomic e…

    8b8b7e8
  2. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    performancePerformance or resource usagePerformance or resource usage
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Jun 3, 2026
  3. picnixz
    added this to Pickle and copy issues 🥒on Jun 3, 2026
  4. gaborbernat
    added a commit that references this issue on Jun 3, 2026

    pythongh-150815: Speed up copy.deepcopy() of containers with atomic e…

    0588c61
  5. gaborbernat commented on Sep 23, 2026

    @gaborbernat
    gaborbernat
    on Sep 23, 2026
    ContributorAuthor
    More actions

    Closing: the change in #150822 was judged too much complexity for the gain (#150822 (comment)). A C implementation of deepcopy would be the route for larger speedups.

    Reacted by Maxim Martynov
  6. gaborbernat
    closed this as not plannedon Sep 23, 2026
  7. github-project-automation
    moved this to Done in Pickle and copy issues 🥒on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    • Pickle and copy issues 🥒
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.