Feature or enhancement
Proposal:
We can improve performance of cpython by using stealing methods (_PyList_AppendTakeRef, _PyDict_SetItem_Take2, PyTuple_FromPairSteal etc.) instead of the normal ones. Using stealing methods we typically avoid an incref/decref pair and sometimes error handling is simplified. We should only make changes where it makes a performance impact, the code is not more complex and the modules or methods affected are performance critical.
A list of possible cases (there might be more). The issue is open for anyone to work on.
| Location |
Module / context |
Helper |
Modules/_csv.c:688 |
csv reader, per field |
_PyList_AppendTakeRef |
Modules/pyexpat.c:472 |
pyexpat StartElement, per attribute |
_PyDict_SetItem_Take2 |
Modules/_elementtree.c:3351 |
ElementTree C accel attrib dict |
_PyDict_SetItem_Take2 |
Modules/_io/bytesio.c:577 |
io.BytesIO.readlines |
_PyList_AppendTakeRef |
Modules/_io/iobase.c:756 |
io.IOBase.readlines (generic) |
_PyList_AppendTakeRef |
Objects/frameobject.c:639 & 658 |
frame f_locals / vars() / tracing |
_PyList_AppendTakeRef |
Modules/_pickle.c:5138 |
pickle Pickler memo copy |
_PyDict_SetItem_Take2 |
Modules/_io/textio.c:2337 & 2343 |
io.TextIOWrapper readline (multi-chunk) |
_PyList_AppendTakeRef |
Modules/_asynciomodule.c:1213 |
asyncio future done-callback compaction |
_PyList_AppendTakeRef |
Linked PRs
Feature or enhancement
Proposal:
We can improve performance of cpython by using stealing methods (
_PyList_AppendTakeRef,_PyDict_SetItem_Take2,PyTuple_FromPairStealetc.) instead of the normal ones. Using stealing methods we typically avoid an incref/decref pair and sometimes error handling is simplified. We should only make changes where it makes a performance impact, the code is not more complex and the modules or methods affected are performance critical.A list of possible cases (there might be more). The issue is open for anyone to work on.
Modules/_csv.c:688_PyList_AppendTakeRefModules/pyexpat.c:472_PyDict_SetItem_Take2Modules/_elementtree.c:3351_PyDict_SetItem_Take2Modules/_io/bytesio.c:577_PyList_AppendTakeRefModules/_io/iobase.c:756_PyList_AppendTakeRefObjects/frameobject.c:639 & 658vars()/ tracing_PyList_AppendTakeRefModules/_pickle.c:5138_PyDict_SetItem_Take2Modules/_io/textio.c:2337 & 2343_PyList_AppendTakeRefModules/_asynciomodule.c:1213_PyList_AppendTakeRefLinked PRs