-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Closed
Labels
performancePerformance or resource usagePerformance or resource usagetopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Currently, PyStackRef_FromPyObjectSteal checks if the object is immortal in order to set the Py_TAG_DEFERRED bit.
cpython/Include/internal/pycore_stackref.h
Lines 96 to 105 in 29cbcbd
| static inline _PyStackRef | |
| _PyStackRef_FromPyObjectSteal(PyObject *obj) | |
| { | |
| assert(obj != NULL); | |
| // Make sure we don't take an already tagged value. | |
| assert(((uintptr_t)obj & Py_TAG_BITS) == 0); | |
| unsigned int tag = _Py_IsImmortal(obj) ? (Py_TAG_DEFERRED) : Py_TAG_PTR; | |
| return ((_PyStackRef){.bits = ((uintptr_t)(obj)) | tag}); | |
| } | |
| # define PyStackRef_FromPyObjectSteal(obj) _PyStackRef_FromPyObjectSteal(_PyObject_CAST(obj)) |
This check isn't necessary and has a performance cost that's not made up for by the slightly faster PyStackRef_CLOSE() calls or PyStackRef_Is() checks.
We should simplify PyStackRef_FromPyObjectSteal so that it creates _PyStackRef directly from the PyObject * without setting any tag bits.
Linked PRs
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usagetopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement