Replies: 2 comments 6 replies
-
Making initialization stack intensive was not an intentional thing. And to be honest, I'm not even aware of what specifically is causing it. It could be an easy fix. But it will require investigation. I'm not sure when I'll get to it. But someone can identify specific spots in the code that are using a lot of stack, that will likely make it quicker on my end to fix it. (That's assuming there are some specific spots using a lot of stack. If instead the stack usage is diffuse, then this might be harder to fix.) |
Beta Was this translation helpful? Give feedback.
-
regex/regex-automata/src/meta/strategy.rs Line 153 in 027eebd #[derive(Debug)]
struct Core {
info: RegexInfo,
pre: Option<Prefilter>,
nfa: NFA,
nfarev: Option<NFA>,
pikevm: wrappers::PikeVM,
backtrack: wrappers::BoundedBacktracker,
onepass: wrappers::OnePass,
hybrid: wrappers::Hybrid,
dfa: wrappers::DFA,
} Appears to reserve a significant amount of stack when compiled. Specially for |
Beta Was this translation helpful? Give feedback.
-
Hello,
My use-case is currently quite niche, because I'm running the
regex
crate in the Windows kernel space. One of the problems I've encountered is an excessive stack usage during the initialization (call toRegex::new
orRegexSet::new
).Specifically, the
new
function inregex-automata/meta/strategy.rs
uses ~10kB of stack by itself (or ~20kB withperf-dfa-full
enabled). If the regex initialization finds itself somwehere deeper in the call stack, the usage will become even greater. -Z emit-stack-sizes could be used to dump the stack usage.Luckily, the WDK offers KeExpandKernelStackAndCalloutEx, so I was able to initialize the engine anyway using the extended stack. But I'd rather use this solution only as a guardrail, since it has its limitations - it will not permit to allocate more than ~64kB of stack. The matching part doesn't seem to exhibit similar stack consumption, so the problem is initialization-specific.
In theory,
regex-lite
should consume less stack, since there's much less to initialize. On the other hand, it is much slower (I believe it uses only the PikeVM?) and possibly too slow for the kernel space. Also it lacksRegexSet
support, which offers great performance benefits when there's a large number of regexes.I created a simple program simulating this issue in the Linux user space (using rlimit): https://github.com/Palkovsky/regex-stack-size/blob/master/src/main.rs:
default_features = false, features = ["perf", "unicode"]
default_features = false, features = ["perf", "perf-dfa-full", "unicode"]
Is there currently an intention to make the initialization less stack-intensive?
Beta Was this translation helpful? Give feedback.
All reactions