Skip to content

gh-161469: Add re benchmarks and _sre tail-call jump dispatch - #36

Open
sobolevn wants to merge 1 commit into
masterfrom
gh-161469-sre-tailcall-bench
Open

sobolevn wants to merge 1 commit into
masterfrom
gh-161469-sre-tailcall-bench

Conversation

@sobolevn

@sobolevn sobolevn commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • add a new Tools/scripts/re_bench.py suite covering multiple re features (literal, charset, quantifier, alternation, backref, lookaround) across multiple input sizes
  • document the new benchmark script in Tools/scripts/README
  • add an initial _Py_TAIL_CALL_INTERP path in Modules/_sre/sre_lib.h by applying tail-call dispatch to DO_JUMP transitions, while preserving the existing non-tail-call and computed-goto behavior
  • add ceval-style compiler gating for musttail + preserve_none in the new path

Validation

  • built with tail-call interpreter enabled:
    • CC=clang-19 ./configure --with-tail-call-interp --without-ensurepip
    • make -j4
  • verified compiler tail-call attribute support:
    • clang-19 -O3 -Werror -c /tmp/tailcall_probe.c
  • verified backwards compatibility build path:
    • CC=gcc /workspaces/cpython/sobolevn/cpython/configure --without-ensurepip
    • make -j4 Modules/_sre/sre.o
  • ran tests:
    • ./python -m test -j2 test_re

Benchmark data

Command used for before/after:

  • ./python Tools/scripts/re_bench.py --seconds 0.4 --repeat 5 --write /tmp/re-baseline.json
  • ./python Tools/scripts/re_bench.py --seconds 0.4 --repeat 5 --read /tmp/re-baseline.json --write /tmp/re-after.json

Notable deltas (best-of-5):

  • alternation-search: +4.6% to +9.1% across sizes
  • most other cases: between ~0% and moderate regressions in this first prototype run
  • geometric mean over all 24 case/size entries: 0.983x (about -1.7%)

This is an initial experiment to establish reproducible measurement and a minimal tail-call integration point for _sre; follow-up tuning can iterate on the dispatch strategy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant