Cache the match object in the compiled re pattern
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con l’implementazione del pattern re compilato ed esamina come vengono allocate le corrispondenze riuscite. Usa la suite di test esistente per confermare che il comportamento rimanga invariato, quindi esegui i controlli refleak e lo stress test concorrente su una build free-threaded. Il lavoro è completo quando l’oggetto match morto viene riutilizzato in modo sicuro e il miglioramento delle prestazioni riportato viene mantenuto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- performance
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100