Smaller objects for the free-threading build using smaller integer types for refcount
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
The literature on reference counting for JVM and other GCs show that very few reference counts get to more than 7. This matches up with our stats that should the ratio of refcount ops to object allocations is about 6/7 to 1.
With that in mind, it would make sense to make the C ints used to represent refcounts smaller.
Instead of:
uint32_t ob_ref_local; // local reference count
Py_ssize_t ob_ref_shared; // shared (atomic) reference count
we can use:
uint8_t ob_ref_local; // local reference count
uint32_t ob_ref_shared; // shared (atomic) reference count
using 5 bytes instead of 12.
If ob_ref_local would overflow, we can atomically move some of that count into ob_ref_shared.
if (++op->ob_ref_local == 0) {
atomic_add(&op->ob_ref_shared, 128);
op->ob_ref_local = 128;
}
ob_ref_shared can use the same approach to saturation and immortality that the default build currently does.
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
Es ist keine Datei und kein Test benannt. Beginne mit den Definitionen und Verwendungen von ob_ref_local und ob_ref_shared im free-threading-Build und verfolge anschließend Referenzzählerüberlauf, atomare Aktualisierungen, Sättigung und das Verhalten bei Unsterblichkeit. Die Arbeit ist abgeschlossen, wenn das kleinere Layout funktioniert, ohne die Korrektheit der Referenzzählung oder das angegebene Überlaufverhalten zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c, python
- Bereich
- performance
- Issue-Typ
- Refactoring
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100