Adjust the value in objects' insertion order array to the index - position.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Currently, we store an array of bytes at the end of the inline value array of objects to record the insertion order.
This is expensive as we need to compute not only the value to insert, but where to insert it. Here's the code:
PyDictValues *values = _PyObject_InlineValues(owner_o);
Py_ssize_t index = value_ptr - values->values;
_PyDictValues_AddToInsertionOrder(values, index);
_PyObject_InlineValues requires some lookup, as it depends on tp->basicsize
return (PyDictValues *)((char *)obj + tp->tp_basicsize);
but it is _PyDictValues_AddToInsertionOrder that is the slowest:
int size = values->size;
uint8_t *array = (uint8_t *)&values->values[values->capacity];
array[size] = (uint8_t)ix;
values->size = size+1;
If instead of storing the delta of the index and position, instead of just the index, for the majority of objects the insert order array will go from { 0, 1, 2, 3, 4, ... } to { 0, 0, 0, 0, 0, ... }
And if the delta is zero, we don't need to store anything.
PyDictValues *values = _PyObject_InlineValues(owner_o);
Py_ssize_t index = value_ptr - values->values;
Py_ssize_t delta = index - values->size;
if (delta != 0) {
/* This is the expensive part */
_PyDictValues_AddToInsertionOrder(values, delta);
}
values->size++;
In the JIT we can track the size of the inline values, and know when delta will be zero. Reducing the above code to
values->size = KNOWN_SIZE;
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
Beginne damit, _PyObject_InlineValues und _PyDictValues_AddToInsertionOrder nachzuverfolgen, und untersuche anschließend den im Issue beschriebenen JIT-Pfad, um zu verstehen, wie die Größe der Inline-Werte erfasst wird. Als abgeschlossen gilt die Arbeit, wenn die Speicherung der Einfügereihenfolge das vorgeschlagene Zero-Delta-Verhalten verwendet, ohne die Objekt-Reihenfolge zu ändern, und das betroffene Laufzeitverhalten weiterhin korrekt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c, python
- Bereich
- backend, performance
- Issue-Typ
- Refactoring
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100