-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
gh-138342: Use a common utility for visiting an object's type #138343
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
Conversation
Also use it in _bz2.
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 think we should be smarter here:
- Let's first add your utility without it being used.
- Remove the traverse & GC support for types that are immutable and empty.
- Add the necessary traverse functions for objects whose class is meant to be mutable.
(1) can be achieved independently but (2) and (3) should perhaps be coordinated depending on what we want to backport. I would suggest that we don't change immutability in 3.13 and 3.14 (so we need the traverse functions for those types) but we can do in 3.15 (in which case we won't need this helper).
Nevermind, my comment got cross-posted with #116946 (comment). So apparently, it would be safer to not change the immutability of those types for now. |
Yeah, I found a few other types that don't need this. But as I said in the PR description:
This PR is pretty big already, and I would like to avoid sprinkling in behavior changes. Once your work with #116946 is done, we can strengthen the assertions in |
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.
Apart from the changes that I will revert in #138338 are removed from this PR, we can merge this. Do you want to review it?
Co-authored-by: Adam Turner <[email protected]>
Most of these are cases where the object actually doesn't needs to have GC at all, they are empty objects with immutable types. Instead of adding this why not just remove GC from them? It will help in performance and reduce gc pressure. Also in future when improving the assertions, how would you check for empty objects? |
Something like |
Add
_PyObject_VisitType
in place oftp_traverse
functions that only visit the object's type. This will likely help us catch some bugs through assertions, as we can ensure that this only applies to mutable heap types (and thus are subject to reference cycles). For now, I've kept the assertions relatively relaxed to make it easier to review, but I'll strengthen those assertions and address any bugs in a follow-up.Sorry about the flood of pings, codeowners.