ReviewOS

also looking at this

zig-utils/zig-regex

Port to latest zig-master

#2
Closed armagidon-exception wants to merge main into main
53 files +1149 -1017
docs/BENCHMARKS.mdmodified+26-21
Changes to docs/BENCHMARKS.md
@@ -32,12 +32,12 @@ All benchmarks run with 10,000 iterations unless otherwise noted.
3232
3333### Core Operations
3434
35| Pattern | Input | Avg Time | Ops/sec | Description |
36|---------|-------|----------|---------|-------------|
37| `hello` | `hello world` | ~6.87 µs | ~145,000 | Simple literal match |
38| `a+` | `aaaa` | ~5.50 µs | ~182,000 | Quantifier (one or more) |
39| `\d+` | `12345` | ~5.01 µs | ~200,000 | Digit character class |
40| `hello` (case-insensitive) | `HELLO` | ~4.62 µs | ~216,000 | Case-insensitive match |
35| Pattern | Input | Avg Time | Ops/sec | Description |
36| -------------------------- | ------------- | -------- | -------- | ------------------------ |
37| `hello` | `hello world` | ~6.87 µs | ~145,000 | Simple literal match |
38| `a+` | `aaaa` | ~5.50 µs | ~182,000 | Quantifier (one or more) |
39| `\d+` | `12345` | ~5.01 µs | ~200,000 | Digit character class |
40| `hello` (case-insensitive) | `HELLO` | ~4.62 µs | ~216,000 | Case-insensitive match |
4141
4242### Detailed Results
4343
@@ -65,24 +65,24 @@ Test 4: Case-insensitive matching...
6565
6666### Time Complexity
6767
68| Operation | Complexity | Notes |
69|-----------|------------|-------|
70| Compile | O(p) | p = pattern length |
71| isMatch | O(n × m) | n = input length, m = NFA states |
72| find | O(n × m × k) | k = starting positions attempted |
73| findAll | O(n × m) | Amortized over all matches |
74| replace | O(n + r) | r = replacement length |
75| replaceAll | O(n × m + r) | Includes matching cost |
76| split | O(n × m) | Plus array allocation |
68| Operation | Complexity | Notes |
69| ---------- | ------------ | -------------------------------- |
70| Compile | O(p) | p = pattern length |
71| isMatch | O(n × m) | n = input length, m = NFA states |
72| find | O(n × m × k) | k = starting positions attempted |
73| findAll | O(n × m) | Amortized over all matches |
74| replace | O(n + r) | r = replacement length |
75| replaceAll | O(n × m + r) | Includes matching cost |
76| split | O(n × m) | Plus array allocation |
7777
7878### Space Complexity
7979
80| Component | Complexity | Notes |
81|-----------|------------|-------|
82| Compiled Regex (NFA) | O(p) | Persistent storage |
83| VM Execution | O(m × c) | c = capture group count |
84| Match Results | O(r) | r = number of results |
85| Temporary (AST) | O(p) | Freed after compilation |
80| Component | Complexity | Notes |
81| -------------------- | ---------- | ----------------------- |
82| Compiled Regex (NFA) | O(p) | Persistent storage |
83| VM Execution | O(m × c) | c = capture group count |
84| Match Results | O(r) | r = number of results |
85| Temporary (AST) | O(p) | Freed after compilation |
8686
8787### Greedy Matching Performance
8888
@@ -255,11 +255,13 @@ Pattern: "\\d{3}-\\d{4}"
255255### vs. Backtracking Engines (PCRE, Python re)
256256
257257**Advantages:**
258
258259- ✅ **No catastrophic backtracking** - Always linear time
259260- ✅ **Predictable performance** - O(n×m) guaranteed
260261- ✅ **Memory safe** - No stack overflow on deep recursion
261262
262263**Trade-offs:**
264
263265- ❌ **Slower on simple patterns** - More overhead for simple cases
264266- ❌ **No backreferences** - Not currently supported
265267- ❌ **No look-around** - Not currently supported
@@ -267,10 +269,12 @@ Pattern: "\\d{3}-\\d{4}"
267269### vs. DFA Engines (RE2, ripgrep)
268270
269271**Similarities:**
272
270273- ✅ **Linear time** - Both guarantee O(n×m)
271274- ✅ **No backtracking** - Deterministic matching
272275
273276**Trade-offs:**
277
274278- ❌ **NFA simulation** - We don't build full DFA (saves memory)
275279- ❌ **Capture groups** - Our approach is simpler for captures
276280- ✅ **Memory usage** - Lower than full DFA construction
formatting only · 7 hidden lines
Changes to docs/BENCHMARKS.md
@@ -410,6 +414,7 @@ CSV splitting (100,000 rows): ~300ms total formatting only
410414```
411415
412416These are estimates. Actual performance depends on:
417
413418- Pattern complexity
414419- Input characteristics
415420- Hardware specifications