[issue45462] Speed up re.match with pre-compiled patterns

2021-10-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: For reference, caching was introduced in b1aa19515ffdb84c6633ee0344196fd8bd50ade0 21 years ago, and initially it checked for pre-compiled patterns before looking up in the cache. But it was changed 2 months later in

[issue45462] Speed up re.match with pre-compiled patterns

2021-10-15 Thread Jonas H.
Jonas H. added the comment: pat.match() has 110 nsec. Feel free to close the issue and PR if you think this isn't worth changing. -- ___ Python tracker ___

[issue45462] Speed up re.match with pre-compiled patterns

2021-10-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: And compare it with pat.match("asdf"). If the performance is critical, use methods of pre-compiled patterns. -- ___ Python tracker ___

[issue45462] Speed up re.match with pre-compiled patterns

2021-10-15 Thread Jonas H.
Jonas H. added the comment: I agree with your statement in principle. Here are numbers for the slowdown that's introduced: Without the change: ./python.exe -m timeit -s 'import re'\n'[re.compile(f"fill_cache{i}") for i in range(512)]'\n'pat = re.compile(".")' 're.match(pat, "asdf")'

[issue45462] Speed up re.match with pre-compiled patterns

2021-10-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Calling re.math() with a pre-compiled pattern is an uncommon case. Common cases are calling re.math() with a string pattern and calling the math() method of a pre-compiled pattern. Your change speeds up an uncommon case but slows down a common case.

[issue45462] Speed up re.match with pre-compiled patterns

2021-10-13 Thread Jonas H.
Change by Jonas H. : -- keywords: +patch pull_requests: +27224 stage: -> patch review pull_request: https://github.com/python/cpython/pull/28936 ___ Python tracker ___

[issue45462] Speed up re.match with pre-compiled patterns

2021-10-13 Thread Jonas H.
New submission from Jonas H. : re.match(p, ...) with a pre-compiled pattern p = re.compile(...) can be much slower than calling p.match(...). Probably mostly in cases with "easy" patterns and/or short strings. The culprit is that re.match -> re._compile can spend a lot of time looking up p