Actually it's a post-optimization.
After the first full backtrack (from "a" to end/FAIL) the 2nd regex reports
and runs from "b" to FAIL.
After that the cached results are later used to see that no match is possible and backtracking is stopped. That's why the formula is n+(n-1)
So it's not that the 1st regex with the recursion is very bad¹, it's just that the second is very clever.
Hint: use re "debug" to see the details.
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
¹) there still might be a memory leak somewhere, but who is using recursion to this extremes anyway?
In reply to Re^3: Recursive sub-pattern spectacularly slow, what's wrong? (me, or just this use case, or a bug?)
by LanX
in thread Recursive sub-pattern spectacularly slow, what's wrong? (me, or just this use case, or a bug?)
by Anonymous Monk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |