Skip to content
airliftPublic

About

High-performance, linear-time regular expression engine for UTF-8 Slice data, supporting RE2, Java, Rust, Trino, and SQL LIKE patterns

Resources

Stars

13 stars

Watchers

0 watching

Forks

Repository files navigation

Regulator logo

Regulator

Regulator is a high-performance regular-expression engine for UTF-8 Slice data. It supports five pattern languages: the Rust regex crate, RE2, Java Pattern, and Trino regular expressions compile onto one engine, and Trino SQL LIKE has its own matcher. Each search runs in linear time with bounded memory, making it a good fit for data-processing systems that compile patterns once and apply them repeatedly.

For many common patterns, Regulator can also generate a dedicated JVM class at compile time. A caller that holds the pattern as a constant calls that code directly, and the JIT can inline it; generated patterns typically run about 1.5–2× faster than the default compiled form.

Performance

Regulator's speedup over each library for everyday expressions and larger text-processing workloads:

Compared with Everyday expressions Text processing
Rust regex crate 2.0× faster 1.7× faster
Native RE2 4.4× faster 6.6× faster
Java regex 5.7× faster 34.3× faster
Trino regex (Joni) 4.7× faster 26.1× faster
Trino LIKE 6.0× faster —

Source: Regulator 2.1 preliminary results 47eaddfd9abc40519b1349278716a2fc49ae7d5d. R9g with native access enabled and patterns reused. Geometric mean of per-workload time ratios; input conversion excluded.

See the interactive benchmark report for individual workloads, Intel and Graviton results, absolute time differences, and pure-Java comparisons.

Results depend on the pattern, input, pattern reuse, CPU architecture, and native memory access. Comparisons measure corresponding public operations using each library's own input and output types. Input conversion is outside the timings.

Choosing a language

Regulator's four regex languages compile onto the same matching engines, so the language barely changes matching speed. On everyday expressions they run within about 1% of each other:

Time relative to Rust R9g R8i
Rust regex 1.00× 1.00×
RE2 0.99× (0.98–1.00) 1.00× (0.99–1.02)
Java regex 1.00× (0.99–1.02) 1.01× (0.98–1.03)
Trino regex 1.00× (0.95–1.06) 1.01× (0.94–1.10)

Regulator's own time for each language, relative to its Rust language: geometric mean of per-workload ratios, with the 10th–90th percentile range, over reused contains and count. Native access enabled. Source: Regulator 2.1 preliminary results 47eaddfd9abc40519b1349278716a2fc49ae7d5d.

Text processing shows larger differences: Java takes about 1.1× and Trino about 1.3× Rust's time (geometric mean), though the median workload takes the same time in every language. Rust's byte mode and RE2's Latin-1 mode match bytes, while Java and Trino match characters, and a few workloads take slower routes in Java and Trino today, mainly Unicode word boundaries and Trino's full case folding.

Supported languages

Regulator provides separate compilers for:

  • the Rust regex crate's pattern language
  • RE2 syntax
  • the regular subset of Java Pattern
  • Trino regular-expression syntax
  • Trino SQL LIKE patterns

Usage

Patterns and inputs are Slice values. Match positions are byte offsets within the input Slice, and captures are zero-copy views of it. If your data starts as Java strings, convert it explicitly. UTF-8 encoding and decoding can allocate and scan the entire value.

import io.airlift.regulator.Re2;
import io.airlift.regulator.RegexpMatcher;
import io.airlift.slice.Slice;

import static io.airlift.slice.Slices.utf8Slice;

Re2 re2 = Re2.compile(utf8Slice("(?<key>[a-z]+)=(?<value>[0-9]+)"));
Slice input = utf8Slice("user=alice count=42");

RegexpMatcher matcher = re2.matcher(input);
while (matcher.find()) {
    Slice key = matcher.group("key");
    Slice value = matcher.group("value");
}

Share compiled patterns across threads, but give each thread its own matcher. A RegexpMatcher keeps mutable state and reuses its matching workspace.

Use the compiler matching the pattern's language:

Slice patternBytes = utf8Slice("[a-z]+");
RustRegexp rustRegexp = RustRegexp.compile(patternBytes);
Re2 re2 = Re2.compile(patternBytes);
JavaRegexp javaRegexp = JavaRegexp.compile(patternBytes);
TrinoRegexp trinoRegexp = TrinoRegexp.compile(patternBytes);
TrinoLikePattern likePattern = TrinoLikePattern.compile(patternBytes);

The same text can compile in two languages and mean different things.

Generated bytecode

Regulator can compile an eligible pattern into its own JVM class. The option is off by default and never changes results:

Re2 re2 = Re2.compile(
        utf8Slice("https?://([^/]+)/"),
        Re2.Options.defaults().setGenerateBytecode(true));
boolean generated = re2.usesGeneratedBytecode();

usesGeneratedBytecode() reports whether the pattern got a class; a pattern that is not eligible compiles as usual. The speedup comes when the caller binds the pattern as a constant, so the JIT can inline its generated code; see Binding a compiled pattern for details.

Dependency

Regulator is published as io.airlift:regulator and requires Java 25 or newer. Releases are tested on Java 25 and the current feature release used by Trino, including short-term-support releases.

<dependency>
    <groupId>io.airlift</groupId>
    <artifactId>regulator</artifactId>
    <version>2.1</version>
</dependency>

See the 2.1 release and API documentation. Regulator's runtime dependencies are Slice and the airlift classfile library. The classfile library is loaded only when a pattern is compiled with generated bytecode.

Runtime acceleration

The four regex compilers share Regulator's RE2-based matching engines. SQL LIKE has its own parser, planner, and wildcard matcher. It shares specialized literal matchers with the regex engines where the languages behave the same way.

Regulator works without special JVM flags. These optional flags enable faster paths without changing matching behavior:

--add-modules jdk.incubator.vector
--enable-native-access=ALL-UNNAMED

The Vector API lets Regulator scan multiple input bytes at a time when looking for candidate matches. It is used when the JVM's preferred byte vector holds 16 to 64 bytes; other JVMs use the scalar or SWAR scanners. Native access lets eligible DFA searches keep an optional pointer table of DFA transitions in a small native memory allocation; the DFA's other transition tables stay on the Java heap.

This is native memory, not native code or a JNI library. It is entirely internal; the API never exposes native pointers. Patterns, inputs, captures, and results remain Java and Slice data. Without these flags, Regulator uses scalar or SWAR scanners and keeps the same DFA pointer table in a Java array.

Either table avoids following Java object references for DFA table rows and decoding compressed references, also known as compressed oops. In native memory an entry is the next row's address; in a Java array it is the next row's offset, which costs an addition per transition. The effect of native access depends on the pattern, input, and matching engine; LIKE-only routes do not use the DFA.

Enable both flags. The benchmark report runs every row with the Vector API and includes separate native-access and pure-Java results; its pure-Java results use the Java-array table. The FAQ explains the benefit of each flag.

Documentation

Building

./mvnw clean install

License

Regulator is licensed under the Apache License 2.0. It includes a Java port of RE2; the required RE2 copyright and BSD license notice are provided in LICENSE-re2.txt. Regulator also implements the Rust regex crate's pattern language; the notice for its Rust test data, which also covers its port of the aho-corasick crate's automaton, is in LICENSE-rust-regex.txt. The notice for its Unicode data, including the Rust property names, is in LICENSE-unicode.txt. The jar carries these notices under META-INF/. Test and benchmark data taken from other projects carries its notices beside it in src/test/resources; start with THIRD-PARTY-NOTICES.md.

About

High-performance, linear-time regular expression engine for UTF-8 Slice data, supporting RE2, Java, Rust, Trino, and SQL LIKE patterns

Resources

Stars

13 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages