Skip to content

selabel: Use hybrid DFA+PCRE2 fallback for regex matching#329

Merged
cgwalters merged 1 commit into
composefs:mainfrom
cgwalters:selabel-perf
Jun 25, 2026
Merged

selabel: Use hybrid DFA+PCRE2 fallback for regex matching#329
cgwalters merged 1 commit into
composefs:mainfrom
cgwalters:selabel-perf

Conversation

@cgwalters

Copy link
Copy Markdown
Collaborator

Originally (before 835c986) we were compiling all the regexps into a single DFA, which allowed huge amounts of optimization.

In that commit we added support for lookbehinds, but this is dramatically (easily 5000x) slower to evaluate each regexp individually.

Since the default Fedora SELinux policy doesn't have any lookbehinds, let's first try the previous strategy of building a single DFA with all regexps at once.

If that fails, then our fallback strategy is to parse each one, and ones we can parse with the main regex_syntax crate we put into the single DFA, the others go into individual PCRE regexps.

This gives us nearly all the performance back.

Assisted-by: OpenCode (claude-opus-4-6)

Originally (before 835c986) we were compiling all the regexps
into a single DFA, which allowed huge amounts of optimization.

In that commit we added support for lookbehinds, but this is
dramatically (easily 5000x) slower to evaluate each regexp
individually.

Since the default Fedora SELinux policy doesn't have any lookbehinds,
let's first try the previous strategy of building a single DFA
with all regexps at once.

If that fails, then our fallback strategy is to parse each one,
and ones we can parse with the main regex_syntax crate we put
into the single DFA, the others go into individual PCRE regexps.

This gives us nearly all the performance back.

Assisted-by: OpenCode (claude-opus-4-6)
Signed-off-by: Colin Walters <walters@verbum.org>

@giuseppe giuseppe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cgwalters cgwalters added this pull request to the merge queue Jun 25, 2026
Merged via the queue into composefs:main with commit 679a342 Jun 25, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants