Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Bobronium/copium

Repository files navigation

Fast drop-in replacement for copy.deepcopy().

Copium Logo
Benchmark results bar chart

Highlights

  • ⚡ 4-28x faster than copy.deepcopy() on builtin types
  • 🧠 uses ~44% less memory than copy.deepcopy() on average
  • 🧪 passes all tests in CPython/Lib/test/test_copy.py
  • 🎯 behaves exactly the same as copy.deepcopy() for all datamodelzoo.CASES
  • 🛡️ tested for refcount, recursion, threading and memo edge cases
  • 🐍 pre-built wheels for Python 3.10-3.14 on Linux/macOS/Windows (x64/ARM64)
  • 🔓 passes all tesee-frts on threaded Pyth buildons

Installation

Warning

This is an alpha version.

pip install copium

Usage

Simply export COPIUM_PATCH_DEEPCOPY=1 before running your application. You don't have to change a single line of code:

cat example.py

from copy import deepcopy

assert deepcopy(x := []) is not x

COPIUM_PATCH_DEEPCOPY=1 python example.py

To enable the patch manually:

import copium.patch

copium.patch.enable()

To use manually:

from copium import deepcopy

assert deepcopy(x := []) is not x

The copium module includes all public declarations of stdlib copy module, so it's generally safe to:

- from copy import copy, deepcopy, Error
+ from copium import copy, deepcopy, Error

About

Fast drop-in replacement for copy.deepcopy().

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •