GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++ Performance Win

libstdc++: Continue with regex DFS traversals without next frames

Optimized regex DFS execution in libstdc++ by avoiding unnecessary stack frame operations for repeated matches.

This patch revises the iterative DFS regex executor to avoid pushing and popping stack frames when a match is expected to continue. For repeated subexpressions, the executor now attempts to consume the state immediately, keeping values in registers to minimize memory accesses and function call overhead. This significantly improves performance for patterns involving repetitions, while maintaining the memory usage improvements of the original iterative approach.

In Details

The iterative DFS regex executor, which replaced a recursive implementation, previously introduced overhead by always saving and restoring bookkeeping frames, even for simple continuations like in _M_rep_once_more. This commit modifies _m_handle_* methods to return a _StateIdT. For DFS, this allows the caller to consume the state directly if it returns to the repeat state, eliminating redundant frame operations. Methods involved are marked always_inline to ensure register pressure is managed and stack traffic avoided.

For Context
DFS regex executor
The Direct Finite State Machine implementation within libstdc++'s regex library. It is an iterative approach to executing regular expression matching.
stack frame
A region of memory on the call stack used to store function call information, including local variables and return addresses. Pushing and popping these frames incurs overhead.
always_inline
A function attribute that suggests to the compiler that the function should be inlined at every call site, even if it would normally not be considered for inlining.
AAPCS
The ARM Architecture Procedure Call Standard, which defines conventions for function calls, including how parameters are passed and return values handled. Inlining can avoid AAPCS overhead.
Filed Under: libstdc++regexoptimizationperformance