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-84436: Implement Immortal Objects #19474
gh-84436: Implement Immortal Objects #19474
Conversation
This is ready to review, the CI is finally green. Really no idea why the newly added GC tests are failing on Windows and unfortunately I don't have a Windows machine to debug this. |
Also looping in @vstinner. Finally got around upstreaming this patch since you recently wrote about this on your C-API Improvement Docs |
My first reaction is that this shouldn't become part of the default build because most Python users will not make use of it and then it becomes pure extra overhead. However, I know for some people that it is a useful feature (e.g. pre-fork server architecture that exploits copy-on-write OS memory management). I would use it myself since I write web applications with that style. Would it be okay to make this a compile time option, disabled by default? I think in general it is a bad idea to have too many of those types of build options. It makes code maintenance and testing more difficult. Some example build variations from the past that caused issues: thread/no-threads, Unicode width, various debug options (@vstinner removed some of those). So, I'm not super excited about introducing a new build option. Is it possible we can leverage this extra status bit on objects to recover the lost performance somehow? A couple years ago I did a "tagged pointer" experiment that used a similar bit. In that case, small integers became one machine word in size and also become immortal. Another thought: when you did your testing, were any objects made immortal? I would imagine that, by default, you could make everything immortal after initial interpreter startup. You are paying for an extra test+branch in INCREF and DECREF but for many objects (e.g. None, True, False, types) you avoid dirtying the memory/cache with writes to the reference count. |
@nascheme you should definitely join the conversation happening in the bug report of this PR https://bugs.python.org/issue40255
Exactly, this change might be a feature for CPython power users
Yeah, that's probably the best option. That's also the consensus in the bug report thread (if the change is approved)
Yeah that's one of the drawbacks. That being said, I can help with setting up the travis build to integrate this change if needed (cc @vstinner).
We can indeed, I think somebody also mentioned that in the bug report. A potentially good place could be In theory we could optimize even further to reduce the perf cost. By leveraging saturated adds and conditional moves we could remove the branching instruction. I haven't explored this further since the current PR was good enough. Personally, I favor the current PR, but this could be changed to:
|
Not only that, we would need specialized buildbots to test the code base with this option activated in a bunch of supported platforms and that raises the maintainance costs. |
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.
This feature sounds controversial, so I block it until a consensus can be reached.
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 |
@ericsnowcurrently Alright, I figured it out. It's a problem with C++ and more specifically std:c++20 which some builds use as an option. It has this clause where we cannot mix designated-initializers with non-designated-initializers. The problem is that with the replacement of To fix the "mix of designated and non-designated initializers" error in I think the solution here is to either remove the designated initializers in Also cc @arhadthedev since it's related to what you wrote above. |
@ericsnowcurrently I think it's working, in the meantime, would it be possible to revert 5c00a62 to make sure we get a clean build here? |
Yeah, I'll look into that. |
If you want to schedule another build, you need to add the |
@ericsnowcurrently Alright, this seems to have fixed the issue designated initializers issue! Also, for some reason, a new warning came up with Mac/Clang build around "missing braces" and it causes test_cppext to fail. Looking into it already, should be easy to fix, you can see the sample error below. Separately, there are still failures with the broken tests on the main branch. We are super close now! Error Sample:
|
@ericsnowcurrently Fixed the Clang/MacOS problem. Given that we removed the designated initializers, the ob_refcnt type had issues with the clang compiler. Since we made the field a union, we now need braces to explicitly indicate that we are initializing the union. After adding them, the build was fixed and we should be back to green on the Mac/Clang builds. Could you help me with a buildbot trigger? :) |
If you want to schedule another build, you need to add the |
@ericsnowcurrently I think we are good to go now. It seems like all the remaining test failures are due to Let me know how you would like to proceed! |
They are. The cause is Lines 117 to 132 in 5c00a62
|
Indeed, the module exports Line 1377 in a9b31ab
Line 1397 in a9b31ab
Lines 1411 to 1416 in a9b31ab
I have no idea why some buildbots cannot import |
congrats @eduardo-elizondo!!! |
Thanks for all the hard work you put in and for being so very patient. |
Three years in the making and it's finally there! Huge shoutouts to @ericsnowcurrently for working together with me throughout the years to get this all the way through, you rock!! Also, thanks @markshannon @gvanrossum and @pablogsal for being a sounding board for ideas, reviews, and coaching on the messaging of the PR / PEP! |
Congrats @eduardo-elizondo! I followed this PR from the beginning, even needed to port the changes (in 2020) into python 3.9 due to the memory issue with multiprocessing for my previous company. At some point, I felt this was not going to be in Python due to the inactivity here (especially the review). |
This is the implementation of PEP683
Motivation
The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime.
Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
https://bugs.python.org/issue40255