Improve speed of stdlib functions by replacing `re` uses
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
We can often find the module re in the standard library modules but it can be replaced (if it is possible). I don't suggest removing it everywhere, there are places where its use is appropriate, but there are also places where it is an unnecessary solution and leads to unpleasant consequences (they can be found below)
Cons of regular expressions and reasons to replace regular expressions with functions and methods:
- We spend time to compile re pattern (one time, but anyway we spend it)
- In most cases simple string methods are faster (according to my benchmarks about 2x)
- We can remove
import rewhich will affect import time - Additionally: I think for those who don't know regular expressions, the code is more difficult to read and therefore difficult to maintain.
[!IMPORTANT]
For those who want to work on the issue, please:
- Read https://devguide.python.org/getting-started/pull-request-lifecycle/ before anything else.
- Select one function to improve. It's easier to review and possibly backport.
- Always report benchmarks using
pyperf,hyperfine, andtunatogether with-X importtimeto compare import times and execution time.- Open a pull request with the following title:
gh-130167: Improve speed of `module.function` by replacing `re`
Linked PRs
- gh-130170
- gh-130242
- gh-130243
- gh-131919
- gh-131925
- gh-131924
- gh-132065
- gh-132666
- gh-143292
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
Lies zuerst den Leitfaden zum Pull-Request-Lebenszyklus und untersuche dann Standardbibliotheksmodule, die re importieren, und wähle eine Funktion zur Verbesserung aus. Vergleiche die bestehende Implementierung mit String-Methoden mithilfe von pyperf, hyperfine und tuna mit -X importtime. Erledigt ist die Aufgabe, wenn eine Funktion Benchmark-Evidenz und einen Pull Request mit dem angeforderten Titelformat hat.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- performance
- Issue-Typ
- Refactoring
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100