Improve performance by using reference stealing methods
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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).
| 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 |
Update: Most cases already have an open PR, for new ones please open a separate issue.
Linked PRs
- gh-150943
- gh-150945
- gh-150995
- gh-151002
- gh-151062
- gh-151209
- gh-151608
- gh-153013
- gh-154860
- gh-155171
- gh-155304
- gh-155922
- gh-155940
- gh-155957
- gh-156055
- gh-156199
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Überprüfe die aufgeführten C-Stellen, einschließlich Modules/_csv.c, Modules/pyexpat.c, Modules/_elementtree.c sowie der Dateien in _io, Objects, _pickle und _asynciomodule. Prüfe zunächst die verknüpften PRs, um festzustellen, welche Fälle bereits abgedeckt sind; alle verbleibenden Arbeiten sollten in ein separates, klar abgegrenztes Issue mit relevanten Performance-Tests aufgeteilt werden. Erledigt bedeutet, dass ein ausgewählter performancekritischer Fall ohne zusätzliche Komplexität geändert wurde und sein Verhalten sowie seine Performance verifiziert wurden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c, python
- Bereich
- backend
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100