Repository navigation
Open
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirperformancePerformance or resource usagePerformance or resource usagetopic-regextype-featureA feature request or enhancementA feature request or enhancement
Description
It already supports computed gotos:
cpython/Modules/_sre/sre_lib.h
Lines 636 to 657 in 4b50f88
| #ifdef HAVE_COMPUTED_GOTOS | |
| #ifndef USE_COMPUTED_GOTOS | |
| #define USE_COMPUTED_GOTOS 1 | |
| #endif | |
| #elif defined(USE_COMPUTED_GOTOS) && USE_COMPUTED_GOTOS | |
| #error "Computed gotos are not supported on this compiler." | |
| #else | |
| #undef USE_COMPUTED_GOTOS | |
| #define USE_COMPUTED_GOTOS 0 | |
| #endif | |
| #if USE_COMPUTED_GOTOS | |
| #define TARGET(OP) TARGET_ ## OP | |
| #define DISPATCH \ | |
| do { \ | |
| MAYBE_CHECK_SIGNALS; \ | |
| goto *sre_targets[*pattern++]; \ | |
| } while (0) | |
| #else | |
| #define TARGET(OP) case OP | |
| #define DISPATCH goto dispatch | |
| #endif |
Maybe adding tail-calling interpreter will give meaningful speed up for all re calls as well? This might speed up a lot of places in the real code almost for free.
This needs to be researched and measured before making a PR.
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirperformancePerformance or resource usagePerformance or resource usagetopic-regextype-featureA feature request or enhancementA feature request or enhancement
Activity
sobolevn commentedon Nov 6, 2026
CC @Fidget-Spinner, maybe you have an opinion on this :)
Fidget-Spinner commentedon Nov 6, 2026
I think I looked at the sre interpreter some time ago and concluded at the time to support things it would be pretty invasive, as some of it has jump targets within labels, and that kind of unstructured control-flow is unsupported by the tailcalling approach. At the very minimum, a refactor of the sre interpreter might be required. I might be remembering wrong and/or thinking of the marshal interpreter though. Anyways, with an AI agent it's probably much easier to do nowdays.