gh-140232: Do not track frozenset objects with immutables#140234
gh-140232: Do not track frozenset objects with immutables#140234vstinner merged 46 commits intopython:mainfrom
Conversation
Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
|
Maybe it is worth to change PyObject *
PyFrozenSet_Alloc(PyTypeObject *type, Py_ssize_t nitems)
{
PyObject *obj = PyType_GenericAlloc(type, nitems);
if (obj == NULL) {
return NULL;
}
_PyFrozenSet_MaybeUntrack(obj);
return obj;
} |
The |
sergey-miryanov
left a comment
There was a problem hiding this comment.
Code looks good to me.
…cpython into frozenset_immutable_tracking
|
Would it be possible to write tests in Python rather than in C? |
I tried, but it is not easy. We have to expose Line 2778 in d78d7a5 And when calling |
IIUC, if you return the first argument from pyset_add then you can test it on the python side. |
Ok, I gave it another try. The first attempt failed, but by using the vectorcall convention I can keep the reference count at 1 also from the Python side. |
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner
left a comment
There was a problem hiding this comment.
LGTM. With one last comment :-)
Nice. Give me one second to double check something. |
The PR is ready from my side! |
sergey-miryanov
left a comment
There was a problem hiding this comment.
Two nitpicks. Otherwise LGTM.
|
Merged, thanks for the many updates! |
In the PR we untrack frozen tuples for the normal constructors. There are a few methods shared between the
setandfrozenset(for exampleset_intersectioninsetobject.c) where we have not added the untracking. (this is possible, but I am not sure this is worthwhile to do).Here is a small script to test the idea:
It measures the performance of garbage collection, and outputs some statistics for the numbers of frozen containers.
Main:
PR
Note: generative ai was used in creating the PR