Improve speed of stdlib functions by replacing `re` uses
未关闭
还没有人认领这个 Issue。
performance
stdlib
type-feature
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先阅读 pull request 生命周期指南,然后检查导入 re 的标准库模块,并选择一个函数进行改进。使用 pyperf、hyperfine 和带有 -X importtime 的 tuna 将现有实现与字符串方法进行比较。当一个函数具有基准测试证据,并且有一个使用所要求标题格式的 pull request 时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- performance
- Issue 类型
- 重构
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 35/100