-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
gh-72793: C implementation of parts of copy.deepcopy #91610
base: main
Are you sure you want to change the base?
Conversation
@pablogsal Would you be able to review this PR? |
@serhiy-storchaka As the latest core develop working on this file, would you be able to review this PR? |
83741a6
to
2f8e489
Compare
af2a201
to
502c747
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel comfortable reviewing the C code, but you will need to add tests to ensure the fallback and C implementation have the same inputs/outputs/etc -- the easiest way would be to duplicate the tests and run one set for the C accelerator and one for the Python version.
A
Misc/NEWS.d/next/Core and Builtins/2022-04-16-20-21-13.gh-issue-72793.qc-BP-.rst
Outdated
Show resolved
Hide resolved
2c18cb6
to
c0fd5c9
Compare
@AA-Turner The Note: in earlier versions of the PR the fallback there was a funny |
If both functions exist and can be theoretically used, both must be tested. You can A |
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
There are some issues with the |
@tiran noted the fallback will be used by PyPy, so it must indeed be tested. I will add the required tests |
We have helper code to block / force imports to test both pure and C accelerated features.
|
I addressed some of the review comments. @serhiy-storchaka Could you indicate which issues with the |
@eendebakpt: can you resolve the conflicts? |
FYI, |
Will look at later this week |
@erlend-aasland The failing tests where due to the recent addition of The PR is ready for review, although I am not sure the item Serhiy raised should be resolved first. See #103035 (comment) and #109498. |
I'll leave that to @serhiy-storchaka. |
Christian is inactive at the moment, so dismissing his review.
For any reviewers: I also created a performance improvement for the python implementation: #114266. Depending on the outcome of that PR and some (minor) changes I want to do to make this work in free-threading I will update the benchmarks. |
@eendebakpt, also consider adapting to free-threading in a follow-up PR; this PR is already a huge diff. |
The following commit authors need to sign the Contributor License Agreement: |
Update of the benchmarks with recent changes to main:
|
To make a fair comparison between current main and the C implementation in this PR I looked at the python implementation again to see whether there are optimizations we do in the C implementation that could also be applied in the Python main. There are quite some options:
I will not make PRs for these, because each of them has a very high likelihood of being rejected because either the performance gain is small or the change would reduce readability or maintainability of the code (for the interested reader: I would give the last option the highest probability of success). |
The original idea and implementation are from @Villemoes. The original issue has been inactive for a long time.
Benchmark on deepcopy of a
dict
anddataclass
:Updated benchmark: (23-12-2022, main at 1ecfd1e)
Updated benchmark: (16-9-2023, main at e57ecf6)
Updated benchmark (10-01-2024)
Benchmark details
Test script
Updated test script
Old test script:
Fixes #72793
Pyperformance results
Pyperformance results show small speedup, although this could very well be a random fluctuation. (there are no explicit calls to deepcopy in the pyperformance tests)
Notes
copy.deepcopy
(see https://peps.python.org/pep-0399/). In the CI we test both the pure python and accelerator version ofdeepcopy
.