Skip to content

Commit

Permalink
gh-91404: Use computed gotos and reduce indirection in re (#91495)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher authored Apr 15, 2022
1 parent d104f4d commit 1b34b56
Show file tree
Hide file tree
Showing 6 changed files with 483 additions and 348 deletions.
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ Optimizations
becomes 272 bytes from 352 bytes on 64bit platform.
(Contributed by Inada Naoki in :issue:`46845`.)

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


Faster CPython
==============
Expand Down
7 changes: 4 additions & 3 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1351,11 +1351,12 @@ regen-stdlib-module-names: build_all Programs/_testembed
$(UPDATE_FILE) $(srcdir)/Python/stdlib_module_names.h $(srcdir)/Python/stdlib_module_names.h.new

regen-sre:
# Regenerate Modules/_sre/sre_constants.h from Lib/re/_constants.py
# using Tools/scripts/generate_sre_constants.py
# Regenerate Modules/_sre/sre_constants.h and Modules/_sre/sre_targets.h
# from Lib/re/_constants.py using Tools/scripts/generate_sre_constants.py
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/generate_sre_constants.py \
$(srcdir)/Lib/re/_constants.py \
$(srcdir)/Modules/_sre/sre_constants.h
$(srcdir)/Modules/_sre/sre_constants.h \
$(srcdir)/Modules/_sre/sre_targets.h

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Improve the performance of :mod:`re` matching by using computed gotos (or
"threaded code") on supported platforms and removing expensive pointer
indirections.
Loading

0 comments on commit 1b34b56

Please sign in to comment.