Repository navigation
Evaluate feature flag regex conditions in linear time - #13487
Draft
leoromanovsky wants to merge 3 commits into
Draft
leoromanovsky wants to merge 3 commits into
leoromanovsky wants to merge 3 commits into
Conversation
Contributor
Contributor
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
Replace java.util.regex for MATCHES and NOT_MATCHES with tiers like the Rust evaluator: literal checks for patterns that are only text, checks that need no engine for .*, .+ and \b-literal patterns, and RE2/J with required prefix and suffix checks for all other patterns. A long attribute value can no longer make one evaluation backtrack for milliseconds. Use the dialect of the Rust regex crate, which libdatadog uses: $ matches only at the end of the input, . does not match a line feed, the u flag is accepted, and lookaround, backreferences and atomic groups are a parse error. The parser compiles each distinct pattern once per configuration.
- Read each multi-character escape (\p{..}, \pX, \x{..}, \xHH, octal) as
one token, so that its characters are not a required literal suffix.
- Translate \d, \D, \s and \S to the Unicode classes of the Rust regex
crate. Reject \Q, class set operations and nested classes, which the
Rust crate rejects or reads differently from RE2/J.
- Remove a - that is left without a flag after the u flag is removed.
- Keep a surrogate pair together when a quantifier follows it.
- Return an unmodifiable list of required suffixes.
- Share the group and alternation helpers, remove the unused pattern
field, and use matches() in place of an expectMatch parameter.
- Move the parser tests to UniversalFlagConfigParserTest.
- Add a JMH benchmark that compares java.util.regex with RegexMatcher.
The base scale benchmark cannot run the regex suite, because the JDK engine does not finish its backtracking cases. With the linear-time matcher it does, so add its literal and backtracking case files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leoromanovsky
force-pushed
the
leo.romanovsky/ffe-regex-linear-time
branch
from
November 17, 2026 01:00
ad69415 to
a571f3a
Compare
leoromanovsky
changed the base branch from
master
to
leo.romanovsky/ffe-scale-suite-benchmark
November 17, 2026 01:00
This was referenced Nov 17, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Does This Do
This PR is stacked on #13485, which adds the scale-suite benchmarks and the
masterbaseline. Review only the commits after it.The FFE provider now evaluates MATCHES and NOT_MATCHES in linear time, with the dialect of the Rust
regexcrate that libdatadog uses. A long attribute value can no longer make one evaluation backtrack for milliseconds.Motivation
java.util.regexbacktracks. On a 2 KB attribute value that does not match, the customer pattern shape.*@(site-a|site-b)\.example$takes about 15 ms for each evaluation. A chain such as.*.*.*.*.*=does not finish within 5 s. Attribute values come from the application (emails, user agents), so this is a latency risk and a ReDoS risk. ReDoS is a denial of service that uses slow regular expressions.Java also gives different results from the Rust-based SDKs (libdatadog) for some patterns. For example,
$before a final line feed matches in Java but not in Rust, and lookahead patterns match in Java but are a parse error in Rust.Changes
RegexMatcher. At parse time, it gives each pattern the cheapest matcher with the same result, in the same order of tiers as the Rust evaluator (dd-sourcerkyv/regex.rs):equals,startsWith,endsWith,contains) for patterns that are only text, with anchors, a leading or trailing.*, and groups of literal alternatives..*and the empty pattern always match;.+; and\bliteral\bwith Unicode word boundaries.com.google.re2j, already in the version catalog), a linear-time engine. A required literal prefix, or a set of required literal suffixes, is checked first.\dand\sbecome Unicode classes.uflag is removed.\Q, class set operations and nested classes are rejected.RegexMatcherBenchmark(JMH) to comparejava.util.regexwithRegexMatcherfor each tier.Scale suite results
Same machine and settings as the #13485 baseline: AWS workspace, Intel Xeon Platinum 8175M, 16 vCPUs, JDK 21.0.10, JMH AverageTime, 1 fork, 3 warm-up and 5 measurement iterations of 2 s,
-prof gc. Each row is the mean over the cases of the file. The runs were back to back.master(#13485)scale/regex(2 KB inputs, 300 duplicate conditions)scale/regex-many(1,000 distinct patterns, 500 alternatives, counted repetition)scale/rules(oneMATCHESin each rule)regex/backtrackingregex/literalsmasterscaleparse timescaleallocated by one parsescaleretained heapThis PR adds the
literalsandbacktrackingcase files of theregexsuite toScaleSuiteBenchmark, because the JDK engine onmasterdoes not finish the backtracking cases.Decisions
\Q. The flag is dropped withPARSE_ERROR, as libdatadog does and as the shared casetest-case-invalid-regex-isolation.jsonexpects. Before this change, Java evaluated these patterns.dd-trace-core, IAST). A DFA tier, as in Rust, could make complex patterns on short inputs faster, but it needs a memory limit and more code.$does not match before a final line feed..matches\r.\dand\sare Unicode.[:alnum:]to\p{Alnum}) is removed. Bracketed POSIX classes, such as[[:alnum:]], still work.RegexMatcherJavadoc:\wand\buse ASCII word characters.\Dand\Sinside a bracketed class are ASCII.xandRflags,\<,\>,\b{...}, class set operations, and nested repetition such asa*+.Additional Notes
Benchmark. I used the
flag-eval-benchharness, with the Datadog provider called through the OpenFeature client andevalPrepared. The runs used Linux x86_64 with JDK 21, pinned to 4 CPUs, on a shared host with a load average of about 4.8. I ran 1.69.0 and this branch back to back. The branch numbers are from before the review-fix commit. The in-module results are in "Scale suite results" above.regex-wildcard-long(2 KB miss)regex-charclass-longregex-wildcardregex-charclassmixed(customer-scale profile)regex-dupregex-complexregex-complex(^u[0-9]{1,N}@(?:a|b|…)\.(?:io|net)$) is slower when the required suffix matches. In that case RE2/J runs its NFA, which is slower than the JDK engine on short inputs.Cross-SDK check. DataDog/ffe-system-test-data#79 adds an opt-in
regexsuite with 63 cases. Its expected results come from libdatadog, and this branch gives the same result for all 63. The submodule pin of #13485 includes that suite, and this PR benchmarks itsliteralsandbacktrackingcase files.Tests. On this stack, all 1,621
dd-openfeaturetests pass, including the canonical fixtures./sdk-reviewran on the first commit, and the second commit fixes its findings.Size. This PR adds more than 1,000 counted lines. The author will add
tag: override pr size check.Jira ticket: [PROJ-IDENT]