Improve speed of stdlib functions by replacing `re` uses
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Trước tiên, hãy đọc hướng dẫn về vòng đời của pull request, sau đó kiểm tra các mô-đun thư viện chuẩn import re và chọn một hàm để cải thiện. So sánh phần triển khai hiện có với các phương thức chuỗi bằng pyperf, hyperfine và tuna với -X importtime. Công việc được xem là hoàn tất khi một hàm có bằng chứng benchmark và một pull request sử dụng định dạng tiêu đề được yêu cầu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- performance
- Loại issue
- Tái cấu trúc
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 35/100