Skip to content

bpo-34636: Use fast path for more chars in SRE category macros. #9170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 11, 2018

Conversation

sir-sigurd
Copy link
Contributor

@sir-sigurd sir-sigurd commented Sep 11, 2018

When handling \s, \d, or \w (and their inverse) escapes in bytes regexes this a small but measurable performance improvement.

https://bugs.python.org/issue34636

@gpshead
Copy link
Member

gpshead commented Sep 11, 2018

Confirming the microoptimization here with a non-debug (opt) build:

~/oss/cpython$ sre-before/python -m timeit -s "import re; s = (b'~' * 1000000); f = re.compile(b'\s\w\d').search" "f(s)"
20 loops, best of 5: 11 msec per loop
~/oss/cpython$ sre-after/python -m timeit -s "import re; s = (b'~' * 1000000); f = re.compile(b'\s\w\d').search" "f(s)"
20 loops, best of 5: 10.1 msec per loop

Those results are consistent across reruns.

@gpshead gpshead changed the title Use fast path for more characters in SRE category macros. bpo-34636: Use fast path for more characters in SRE category macros. Sep 11, 2018
Copy link
Member

@gpshead gpshead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that the valued used make sense and match pyctype where the values are defined.

@gpshead gpshead changed the title bpo-34636: Use fast path for more characters in SRE category macros. bpo-34636: Use fast path for more chars in SRE category macros. Sep 11, 2018
@miss-islington
Copy link
Contributor

@sir-sigurd: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit ec014a1 into python:master Sep 11, 2018
@sir-sigurd sir-sigurd deleted the sre-is-digit branch September 12, 2018 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants