-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-42536: GC track recycled tuples #23623
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
bpo-42536: GC track recycled tuples #23623
Conversation
Misc/NEWS.d/next/Core and Builtins/2020-12-02-20-23-31.bpo-42536.Kx3ZOu.rst
Outdated
Show resolved
Hide resolved
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.
Thanks @brandtbucher for giving this a go. I think that there is a better approach here: force the result to be tracked on the visiting function. This has the advantage of adding only an overhead when the GC calls the visiting function over the zip object as opposed to pay per call to next()
. To be clear, this is what I mean:
a/Python/bltinmodule.c b/Python/bltinmodule.c
index a73b8cb320..b05239c037 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2604,6 +2604,9 @@ static int
zip_traverse(zipobject *lz, visitproc visit, void *arg)
{
Py_VISIT(lz->ittuple);
+ if (!_PyObject_GC_IS_TRACKED(lz->result)) {
+ _PyObject_GC_TRACK(Zz->result);
+ }
Py_VISIT(lz->result);
return 0;
}
When you're done making the requested changes, leave the comment: |
Actually, I am not that sure that this is the better way, as the current approach is formally correct as this should be done when the tuple is mutated (as we do in other containers).
The only reason I think we should consider doing this on the visiting function is due to these results: |
Thanks Pablo. See my thoughts here: https://bugs.python.org/msg382455 If that doesn't worry you at all, I'm fine moving this to the traverse function. |
Oh, wait. I see now that GitHub says you "dismissed" your "stale review". I'm not sure what that means... are we in agreement here to keep this as-is? |
Sorry, I commented it here: https://bugs.python.org/msg382458. I think that unless we see a horrendous performance regression, I prefer this approach than the one I proposed using |
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.
LGTM, but I left some minor coding style remarks (you're free to ignore them).
I also suggest you to copy your NEWS entry as the commit message.
Misc/NEWS.d/next/Core and Builtins/2020-12-02-20-23-31.bpo-42536.Kx3ZOu.rst
Outdated
Show resolved
Hide resolved
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.
🚀
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.
LGTM. Thanks for the latest round of updates ;-)
Thanks @brandtbucher for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9. |
Sorry, @brandtbucher, I could not cleanly backport this to |
Sorry @brandtbucher, I had trouble checking out the |
Several built-in and standard library types now ensure that their internal result tuples are always tracked by the garbage collector: - collections.OrderedDict.items - dict.items - enumerate - functools.reduce - itertools.combinations - itertools.combinations_with_replacement - itertools.permutations - itertools.product - itertools.zip_longest - zip Previously, they could have become untracked by a prior garbage collection. (cherry picked from commit 226a012)
Several built-in and standard library types now ensure that their internal result tuples are always tracked by the garbage collector: - collections.OrderedDict.items - dict.items - enumerate - functools.reduce - itertools.combinations - itertools.combinations_with_replacement - itertools.permutations - itertools.product - itertools.zip_longest - zip Previously, they could have become untracked by a prior garbage collection. (cherry picked from commit 226a012)
GH-23651 is a backport of this pull request to the 3.9 branch. |
GH-23652 is a backport of this pull request to the 3.8 branch. |
Several built-in and standard library types now ensure that their internal result tuples are always tracked by the garbage collector: - collections.OrderedDict.items - dict.items - enumerate - functools.reduce - itertools.combinations - itertools.combinations_with_replacement - itertools.permutations - itertools.product - itertools.zip_longest - zip Previously, they could have become untracked by a prior garbage collection. (cherry picked from commit 226a012)
Several built-in and standard library types now ensure that their internal result tuples are always tracked by the garbage collector: - collections.OrderedDict.items - dict.items - enumerate - functools.reduce - itertools.combinations - itertools.combinations_with_replacement - itertools.permutations - itertools.product - itertools.zip_longest - zip Previously, they could have become untracked by a prior garbage collection. (cherry picked from commit 226a012)
Several built-in and standard library types now ensure that their internal result tuples are always tracked by the garbage collector: - collections.OrderedDict.items - dict.items - enumerate - functools.reduce - itertools.combinations - itertools.combinations_with_replacement - itertools.permutations - itertools.product - itertools.zip_longest - zip Previously, they could have become untracked by a prior garbage collection.
This fixes possibly untracked reference cycles in:
collections.OrderedDict.items
dict.items
enumerate
functools.reduce
itertools.combinations
itertools.combinations_with_replacement
itertools.permutations
itertools.product
itertools.zip_longest
zip
https://bugs.python.org/issue42536