Issue 30340: Optimize out non-capturing groups (original) (raw)

Created on 2017-05-11 09:20 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1542 merged serhiy.storchaka,2017-05-11 09:39
Messages (5)
msg293477 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-11 09:20
Proposed patch makes the regular expression parser produce more optimal tree, mainly due to getting rid of non-capturing groups. This allows to apply an optimization that was forbidden before and makes the regular expression compiler producing more efficient code. For example following expressions are transformed in more optimal form: '(?:x|y)+' -> '[xy]+' '(?:ab) (?:ac)' -> 'a[bc]' r'[a-z] \d' -> r'[a-z\d]' This can speed up matching by 10-25 times. $ ./python -m timeit -s "import re; p = re.compile(r'(?:x
msg293481 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-11 09:34
$ ./python -m timeit -s "import re; p = re.compile(r'[a-z]|[0-9]'); s = ' '*10000+'x'" "p.search(s)" Unpatched: 500 loops, best of 5: 732 usec per loop Patched: 1000 loops, best of 5: 279 usec per loop
msg293501 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2017-05-11 15:31
The PR includes defining and using a _uniq function that is actually a no-op function (it doesn't uniquify, the first line returns the argument, so the rest is skipped). Was that supposed to be removed, or should it actually uniqify?
msg293504 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-11 16:24
Good catch Josh! This return was temporary added for debugging, the function should actually uniqify.
msg293635 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-14 05:32
New changeset 821a9d146bc04a1bc1a9807962990a1f59d692b8 by Serhiy Storchaka in branch 'master': bpo-30340: Enhanced regular expressions optimization. (#1542) https://github.com/python/cpython/commit/821a9d146bc04a1bc1a9807962990a1f59d692b8
History
Date User Action Args
2022-04-11 14:58:46 admin set github: 74525
2017-05-14 06:54:30 serhiy.storchaka set status: open -> closedresolution: fixedstage: patch review -> resolved
2017-05-14 05:32:35 serhiy.storchaka set messages: +
2017-05-11 16:24:03 serhiy.storchaka set messages: +
2017-05-11 15:31:30 josh.r set nosy: + josh.rmessages: +
2017-05-11 09:39:56 serhiy.storchaka set pull_requests: + <pull%5Frequest1641>
2017-05-11 09:34:15 serhiy.storchaka set messages: +
2017-05-11 09:20:53 serhiy.storchaka create