Skip to content

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

Merged
miss-islington merged 2 commits into
python:masterfrom
sir-sigurd:sre-is-digit
Sep 11, 2018
Merged

bpo-34636: Use fast path for more chars in SRE category macros.#9170
miss-islington merged 2 commits into
python:masterfrom
sir-sigurd:sre-is-digit

Conversation

@sir-sigurd

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

Copy link
Copy Markdown
Contributor

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

gpshead commented Sep 11, 2018

Copy link
Copy Markdown
Member

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

@gpshead gpshead left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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