You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NonBacktracking engine is pathologically slow on patterns like "((((((((a)*)*)*)*)*)*)*" and input like "aaaaaaa" which other engines handle fine #84188
Build: 🔎 Result validation: ⚠️ Provided build not found. Provide a valid build in the "Build: 🔎" line. Validation performed at: 8/22/2023 7:37:08 PM UTC
changed the title [-]Outerloop StressTestDeepNestingOfLoops NonBacktracking test is deterministically timing out[/-][+]NonBacktracking engine is pathologically slow on patterns like "((((((((a)*)*)*)*)*)*)*" and input like "aaaaaaa" which other engines handle fine[/+]on Jun 11, 2023
Note that stack helper has switched threads to avoid a stack overflow. There appears to be recursion in System.Text.RegularExpressions.Symbolic.SymbolicRegexNode``1[[System.UInt64, System.Priv ate.CoreLib]].StripEffects(System.Text.RegularExpressions.Symbolic.SymbolicRegexBuilder``1<UInt64>) that we should avoid for efficiency's sake, and that may possibly fix the performance problem on its own.
StripEffects seems to be going down the SymbolicRegexNodeKind.Concat branch of the switch. There are other branches. Can the whole thing be made non recursive?
Aside, there are ~20 places where we're protected with StackHelper.CallOnEmptyStack. Do any of those trigger on a reasonable regex of some kind?
BTW, I think I'd expect to see it in case SymbolicRegexNodeKind.Loop: so perhaps I'm misreading the stack. The structure of the RegexTree is thus:
((((((((((((((((((((a)*)*)*)*)*)*)*)*)*)*)*)*)*)*)*)*)*)*)*)*
Capture index = 0
Atomic
Loop*
Capture index = 1
Loop*
Capture index = 2
Loop*
Capture index = 3
Loop*
Capture index = 4
Loop*
....
Capture index = nnn
One 'a'
I was curious how AI would do on a complex codebase like nonbacktracking, so I asked it to fix this issue autonomously. It produced danmoseley#36 which seems "reasonable" .. ... I don't understand the codebase well enough to OK this for a PR in this repo, though.
@stephentoub the above PR apparently fixed some correctness issues as well. LMK if you want me to make an actual PR, but currently I can't claim to stand behind the change.
Activity
[-]Outerloop StressTestDeepNestingOfLoops NonBacktracking test is deterministically timing out[/-][+]NonBacktracking engine is pathologically slow on patterns like "((((((((a)*)*)*)*)*)*)*" and input like "aaaaaaa" which other engines handle fine[/+]danmoseley commentedon Jun 11, 2023
from PR:
It's just
yield return new object[] { engine, "(", "a", ")*", "a", 2000, 1000 };that is pathological.On the other two variants, NonBacktracking takes less than a second (but still slower than the others)
danmoseley commentedon Jun 11, 2023
cc @olsaarik
danmoseley commentedon Jun 11, 2023
top of the stack looks something like
Note that stack helper has switched threads to avoid a stack overflow. There appears to be recursion in
System.Text.RegularExpressions.Symbolic.SymbolicRegexNode``1[[System.UInt64, System.Priv ate.CoreLib]].StripEffects(System.Text.RegularExpressions.Symbolic.SymbolicRegexBuilder``1<UInt64>)that we should avoid for efficiency's sake, and that may possibly fix the performance problem on its own.StripEffects seems to be going down the SymbolicRegexNodeKind.Concat branch of the switch. There are other branches. Can the whole thing be made non recursive?
Aside, there are ~20 places where we're protected with
StackHelper.CallOnEmptyStack. Do any of those trigger on a reasonable regex of some kind?danmoseley commentedon Jun 11, 2023
BTW, I think I'd expect to see it in
case SymbolicRegexNodeKind.Loop:so perhaps I'm misreading the stack. The structure of the RegexTree is thus:I'll let the area expert take this further 😄
steveharter commentedon Aug 10, 2023
This is still occurring; https://github.com/dotnet/runtime/pull/87369/files did not address all cases.
Adding known issue template to offload from the too-general-purpose error message in #84323.
5 remaining items
jeffschwMSFT commentedon Feb 16, 2024
removing blocking-clean-ci as it has not failed in 30 days
Fix NonBacktracking exponential blowup on nested loops
danmoseley commentedon Mar 6, 2026
I was curious how AI would do on a complex codebase like nonbacktracking, so I asked it to fix this issue autonomously. It produced danmoseley#36 which seems "reasonable" .. ... I don't understand the codebase well enough to OK this for a PR in this repo, though.
danmoseley commentedon Mar 6, 2026
@stephentoub the above PR apparently fixed some correctness issues as well. LMK if you want me to make an actual PR, but currently I can't claim to stand behind the change.
Fix NonBacktracking correctness issues and exponential blowup on nest…
Fix NonBacktracking correctness issues and exponential blowup on nest…
Fix NonBacktracking correctness issues and exponential blowup on nest…