8000 gh-91404: Use computed gotos and reduce indirection in re (#91495) · python/cpython@1b34b56 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b34b56

Browse files
authored
gh-91404: Use computed gotos and reduce indirection in re (#91495)
1 parent d104f4d commit 1b34b56

File tree

6 files changed

+483
-348
lines changed

6 files changed

+483
-348
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,12 @@ Optimizations
520520
becomes 272 bytes from 352 bytes on 64bit platform.
521521
(Contributed by Inada Naoki in :issue:`46845`.)
522522

523+
* :mod:`re`'s regular expression matching engine has been partially refactored,
524+
and now uses computed gotos (or "threaded code") on supported platforms. As a
525+
result, Python 3.11 executes the `pyperformance regular expression benchmarks
526+
<https://pyperformance.readthedocs.io/benchmarks.html#regex-dna>`_ up to 10%
527+
faster than Python 3.10.
528+
523529

524530
Faster CPython
525531
==============

Makefile.pre.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,11 +1351,12 @@ regen-stdlib-module-names: build_all Programs/_testembed
13511351
$(UPDATE_FILE) $(srcdir)/Python/stdlib_module_names.h $(srcdir)/Python/stdlib_module_names.h.new
13521352

13531353
regen-sre:
1354-
# Regenerate Modules/_sre/sre_constants.h from Lib/re/_constants.py
1355-
# using Tools/scripts/generate_sre_constants.py
1354+
# Regenerate Modules/_sre/sre_constants.h and Modules/_sre/sre_targets.h
1355+
# from Lib/re/_constants.py using Tools/scripts/generate_sre_constants.py
13561356
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/generate_sre_constants.py \
13571357
$(srcdir)/Lib/re/_constants.py \
1358-
$(srcdir)/Modules/_sre/sre_constants.h
1358+
$(srcdir)/Modules/_sre/sre_constants.h \
1359+
$(srcdir)/Modules/_sre/sre_targets.h
13591360

13601361
Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.o Python/future.o: $(srcdir)/Include/internal/pycore_ast.h
13611362

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Improve the performance of :mod:`re` matching by using computed gotos (or
2+
"threaded code") on supported platforms and removing expensive pointer
3+
indirections.

0 commit comments

Comments
 (0)
0