Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve speed of stdlib functions by replacingre uses #130167

Open
Labels
performancePerformance or resource usagestdlibPython modules in the Lib dirtype-featureA feature request or enhancement
@donBarbos

Description

@donBarbos

We can often find the modulere 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:

  1. We spend time to compile re pattern (one time, but anyway we spend it)
  2. In most cases simple string methods are faster (according to my benchmarks about 2x)
  3. We can removeimport re which will affect import time
  4. 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:

  • Readhttps://devguide.python.org/getting-started/pull-request-lifecycle/ before anything else.
  • Selectone function to improve. It's easier to review and possibly backport.
  • Always report benchmarks usingpyperf,hyperfine, andtuna together with-X importtime to 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp