[libc-commits] [libc] [libc][regex] Make derivative iterative (PR #246333)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Thu Nov 26 07:48:52 PST 2026


kaladron wrote:

> A random thought, completely optional: Is there a limit on how deep of a recursion do we want to support? Since a single frame is just 8 bytes, you could probably fit several hundred of these in a stack buffer (FixedVector) without needing a heap allocation. And maybe that's enough for everyone?

Two things pushed us toward a small inline buffer with heap growth:

1. GPU stack budget (#236942): default device stacks are only 3 KiB, so putting a few hundred 8-byte frames (~2 KiB) in match() would use most of the stack in one frame. 8 inline frames (64 B) keeps match() under 256 B while staying allocation-free for typical shallow patterns.  This is an area that I'd like to benchmark more on real programs later to see if the thresholds chosen are good for typical cases.

2. Consistency with ExprPool: make_alt represents a1|a2|...|aN as a right-associated spine, so a 300-branch alternation needs depth 300. Since ExprPool already supports up to MAX_NODE_LIMIT (10,000) nodes via heap spill, capping derivative() at a smaller fixed limit would let regcomp accept patterns that regexec then rejects with REG_ESPACE.

Thanks!

https://github.com/llvm/llvm-project/pull/246333


More information about the libc-commits mailing list