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

Skip to content

gh-123745: Improve performance of deepcopy by setting keep alive key in the memo #123746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Sep 5, 2024

Benchmark:

import pyperf
runner = pyperf.Runner()

setup="""
import copy

a={'list': [1,2,3,43], 't': (1,2,3), 'str': 'hello', 'subdict': {'a': True}}

from dataclasses import dataclass

lst = [1, 's']

@dataclass
class A:
    a : int
    
dc = A(123)
list_dc = [A(1), A(2), A(3), A(4)]
"""

runner.timeit(name="deepcopy dict", stmt=f"b=copy.deepcopy(a)", setup=setup)
runner.timeit(name="deepcopy dataclass", stmt=f"b=copy.deepcopy(dc)", setup=setup)
runner.timeit(name="deepcopy small list", stmt=f"b=copy.deepcopy(lst)", setup=setup)
runner.timeit(name="deepcopy list dataclasses", stmt=f"b=copy.deepcopy(list_dc)", setup=setup) 

Results:

deepcopy dict: Mean +- std dev: [main] 11.3 us +- 0.9 us -> [pr] 10.2 us +- 0.1 us: 1.11x faster
deepcopy dataclass: Mean +- std dev: [main] 8.62 us +- 0.29 us -> [pr] 7.74 us +- 0.30 us: 1.11x faster
deepcopy small list: Mean +- std dev: [main] 2.48 us +- 0.10 us -> [pr] 2.20 us +- 0.31 us: 1.13x faster
deepcopy list dataclasses: Mean +- std dev: [main] 34.1 us +- 1.3 us -> [pr] 32.9 us +- 1.0 us: 1.03x faster

Geometric mean: 1.10x faster

See the corresponding issue for further details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant