Cache the match object in the compiled re pattern
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:
re allocates a new match object for every successful match. Matches of one pattern all have the same size, and in a typical loop the previous match dies just before the next one is created.
Keep one dead match object in the compiled pattern and reuse it for the next match instead of allocating. This saves 15-18 ns per successful match (e.g. p.match('42') goes 89 ns → 71 ns, and the string-to-Fraction constructor gains ~6%), with no behavior change. The cache slot is accessed with atomic operations; validated with the test suite, refleak runs, and a concurrent stress test on the free-threaded build.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Linked PRs
- gh-153162
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 mit der Implementierung des kompilierten re-Patterns und untersuche, wie erfolgreiche Matches allokiert werden. Verwende die bestehende Testsuite, um zu bestätigen, dass das Verhalten unverändert bleibt, und führe anschließend refleak-Prüfungen sowie den nebenläufigen Stresstest auf einem free-threaded Build aus. Als erledigt gilt die Aufgabe, wenn das tote Match-Objekt sicher wiederverwendet wird und die gemeldete Leistungsverbesserung erhalten bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- performance
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100