Title: gh-114264: Optimize performance of copy.deepcopy by adding a fast path for atomic types by eendebakpt · Pull Request #114266 · python/cpython · GitHub
Open Graph Title: gh-114264: Optimize performance of copy.deepcopy by adding a fast path for atomic types by eendebakpt · Pull Request #114266 · python/cpython
X Title: gh-114264: Optimize performance of copy.deepcopy by adding a fast path for atomic types by eendebakpt · Pull Request #114266 · python/cpython
Description: By adding a fast path for atomic types we eliminate the overhead of checking the memo argument of deepcopy and the overhead of calling the dispatch method. Benchmark: deepcopy dict: Mean +- std dev: [main] 6.88 us +- 0.08 us -> [pr] 4.65 us +- 0.06 us: 1.48x faster deepcopy dataclass: Mean +- std dev: [main] 6.64 us +- 0.11 us -> [pr] 5.23 us +- 0.07 us: 1.27x faster deepcopy small tuple: Mean +- std dev: [main] 1.07 us +- 0.01 us -> [pr] 924 ns +- 33 ns: 1.16x faster Geometric mean: 1.30x faster Benchmark script: 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 @dataclass class A: a : list b : str c : bool dc=A([1,2,3], 'hello', True) small_tuple = (1, ) """ runner.timeit(name=f"deepcopy dict", stmt=f"b=copy.deepcopy(a)", setup=setup) runner.timeit(name=f"deepcopy dataclass", stmt=f"b=copy.deepcopy(dc)", setup=setup) runner.timeit(name=f"deepcopy small tuple", stmt=f"b=copy.deepcopy(small_tuple)", setup=setup) The approach is similar to the one used in #103005 Issue: gh-114264
Open Graph Description: By adding a fast path for atomic types we eliminate the overhead of checking the memo argument of deepcopy and the overhead of calling the dispatch method. Benchmark: deepcopy dict: Mean +- std dev...
X Description: By adding a fast path for atomic types we eliminate the overhead of checking the memo argument of deepcopy and the overhead of calling the dispatch method. Benchmark: deepcopy dict: Mean +- std dev...
Opengraph URL: https://github.com/python/cpython/pull/114266
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:376b6255-d835-b0dd-9fa6-619d0be1f756 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | 82E4:9CED1:3F5B32:57DDEE:696A75B7 |
| html-safe-nonce | c3439ba6609129b9707bad9e47a12963d5041b1f2ae90e1fb648f5316fd7c580 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkU0OjlDRUQxOjNGNUIzMjo1N0RERUU6Njk2QTc1QjciLCJ2aXNpdG9yX2lkIjoiMzkwOTExMDYyMjc2MTY3ODI2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a4c2dec2b1920bd58dab72fc1fd71b84f9cc8bd3d1baaa61a47895be4a268780 |
| hovercard-subject-tag | pull_request:1685560550 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/114266/checks |
| twitter:image | https://avatars.githubusercontent.com/u/883786?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/883786?s=400&v=4 |
| og:image:alt | By adding a fast path for atomic types we eliminate the overhead of checking the memo argument of deepcopy and the overhead of calling the dispatch method. Benchmark: deepcopy dict: Mean +- std dev... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cfa223d62d272274e0b68350b4bd7741f3ca7498b8c4b8b1bc1e6deabbdbc09d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6a0b6893c221f98f607598e939299fdf5763435d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width