Repository navigation
GH-155728: Untrack const tuples - #156419
sergey-miryanov wants to merge 8 commits into
Conversation
- both used in flowgraph optimizations
|
It is ready for review, could you please take a look? |
|
@Eclips4 Could you please take a look? |
There was a problem hiding this comment.
Add a test for subclasses, please
There was a problem hiding this comment.
Not sure actually whether Python-level subclass would catch this kind of bug (those probably are always tracked?)
There was a problem hiding this comment.
Yeah it seems that Python-level tuple subclasses are always tracked by PyType_GenericAlloc. It has to be a struct sequence created via PyStruct_SequenceNew (which doesn't track), something like this:
st = os.stat(os.curdir)
self.assertFalse(gc.is_tracked(st))
self._tracked_instantly(st + (1,))
self._tracked_instantly((1,) + st)
self._tracked_instantly(st * 2)
self._tracked_instantly(2 * st)| if (_PyObject_GC_IS_TRACKED(aa) || _PyObject_GC_IS_TRACKED(bb)) | ||
| { |
There was a problem hiding this comment.
| if (_PyObject_GC_IS_TRACKED(aa) || _PyObject_GC_IS_TRACKED(bb)) | |
| { | |
| if (_PyObject_GC_MAY_BE_TRACKED(aa) || _PyObject_GC_MAY_BE_TRACKED(bb)) { |
I suppose we can't use _PyObject_GC_IS_TRACKED here because of subclasses. Model like "If the inputs are untracked, their elements are untracked too" only holds for exact tuples. Plus PEP 7 nit
| if (_PyObject_GC_IS_TRACKED(self)) | ||
| { |
There was a problem hiding this comment.
| if (_PyObject_GC_IS_TRACKED(self)) | |
| { | |
| if (_PyObject_GC_MAY_BE_TRACKED(self)) { |
Same here
| The flowgraph optimizer now untracks tuples from the GC when possible. Patch | ||
| by Sergey Miryanov. |
There was a problem hiding this comment.
Let's also mention the changes in tupleobject.c since they are user-visible. E.g. "Now tuples produced by + and * are no longer tracked by the GC when none of their elements can be tracked".
Uh oh!
There was an error while loading. Please reload this page.