Commit ab4039b
authored
perf: v0.12.19 — zero-alloc captures, 95% less memory (#152)
* perf: remove dual transition storage — State.transitions eliminated
Remove transitions []StateID and transitionCount from State struct.
Transitions now stored exclusively in DFACache.flatTrans flat table.
- Remove State.AddTransition(), Transition(), Stride(), TransitionCount()
- Remove Builder.move() (unused after DetectAcceleration simplification)
- Simplify DetectAcceleration/DetectAccelerationFromCached to return nil
- Add DetectAccelerationFromFlat() reading from flat table
- Simplify tryDetectAccelerationWithCache (flatTrans-only path)
- Remove 3 redundant AddTransition calls from determinize
- Update tests: add TestDetectAccelerationFromFlat, remove State transition tests
Memory: ~222MB -> ~150MB (eliminates redundant per-state transition slices)
* perf: Rust-aligned BT visited limit for UseNFA — 72% less memory
Add NewBoundedBacktrackerSmall() with 128K entries (256KB) visited
capacity, matching Rust regex's default visited_capacity.
UseNFA path now creates BT with small limit. When haystack exceeds
BT capacity, falls back to PikeVM (correct for leftmost-first).
UseBoundedBacktracker strategy retains 32M limit for POSIX longest-match.
LangArena LogParser (7MB log, 13 patterns, 10 iterations):
- Total alloc: 89MB -> 25MB (-72%)
- RSS (Sys): 353MB -> 41MB (-88%)
- errors pattern: 66MB -> 2.4MB (-96%)
- Speed: no regression (113-126ms per iter)
* perf: byte-based DFA cache limit — 2MB default like Rust
Replace MaxStates (count) with CacheCapacityBytes (bytes).
Default: 2MB matching Rust regex's hybrid_cache_capacity.
- Add DFACache.MemoryUsage() (mirrors Rust Cache::memory_usage)
- Insert checks MemoryUsage() >= capacityBytes instead of state count
- Config: CacheCapacityBytes (new), MaxStates (deprecated, backward compat)
- Self-adjusting: fewer states for large stride, more for small
- effectiveCapacityBytes() bridges legacy MaxStates to bytes (~100B/state)
* wip: SlotTable-based capture search — greedy loop capture bug
SearchWithSlotTableCapturesAt now uses SlotTable instead of legacy COW.
Works for simple patterns like (foo)(bar), but greedy repetitions
(a+)(b+) lose group start positions during loop iterations.
Root cause: addSearchThread CopySlots overwrites capture slots on each
loop iteration. Need stack-based epsilon closure with RestoreCapture
frames (Rust approach) to preserve capture context through loops.
TODO: Convert recursive addSearchThread to stack-based with save/restore
Status: 2 NFA unit test failures, all meta tests pass (meta still on COW)
* wip: stack-based epsilon closure with RestoreCapture
Converted addSearchThread and addSearchThreadToNext from recursive to
stack-based with captureFrame (Explore + RestoreCapture frames).
Mirrors Rust pikevm.rs FollowEpsilon::RestoreCapture pattern.
Still failing: greedy loop captures (a+)(b+) — per-state SlotTable
overwrites group start on each loop iteration (State visited again
in next generation). Per-thread COW preserves all variants.
Root issue: per-state storage loses capture history across byte
transitions in greedy loops. Need either per-thread indexing or
generation-aware slot preservation.
Status: 2 NFA unit tests fail, all meta tests pass
* feat: dual SlotTable capture tracking — zero-alloc FindSubmatch
Implement Rust-style dual SlotTable (curr/next) for capture propagation
across byte transitions. Stack-based epsilon closure with RestoreCapture
frames preserves capture context through greedy loops.
Key changes:
- Add NextSlotTable + captureStack + currSlots to PikeVMState
- addSearchThread: stack-based with captureFrame (Explore + RestoreCapture)
- addSearchThreadToNext: loads from curr SlotTable, writes to next
- Swap SlotTable/NextSlotTable after each byte (Rust mem::swap pattern)
- Don't clear Visited before seed — prevents SlotTable row overwrite
- Wire meta FindSubmatch to use SlotTable path
- Fix empty match capture groups (buildCapturesFromSlots)
FindAllSubmatch (5 patterns, 50K matches, 800KB input):
- Alloc: 554MB -> 26MB (-95%)
- Mallocs: 12.5M -> 440K (-96%)
- Time: 1.48s -> 0.45s (3.3x faster)
* docs: update CHANGELOG, OPTIMIZATIONS, add ARCHITECTURE.md for v0.12.19
- CHANGELOG: add SlotTable capture tracking entry
- OPTIMIZATIONS: add #10 Dual SlotTable (95% less memory), update version
- ARCHITECTURE.md: new file documenting engine architecture, memory model,
thread safety, and Rust alignment1 parent 921d193 commit ab4039b
18 files changed
Lines changed: 935 additions & 550 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
15 | 44 | | |
16 | 45 | | |
17 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
204 | 207 | | |
205 | 208 | | |
206 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
| 91 | + | |
91 | 92 | | |
92 | | - | |
93 | | - | |
94 | 93 | | |
95 | 94 | | |
96 | | - | |
| 95 | + | |
97 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
98 | 104 | | |
99 | | - | |
| 105 | + | |
| 106 | + | |
100 | 107 | | |
101 | | - | |
| 108 | + | |
102 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
103 | 116 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 117 | + | |
116 | 118 | | |
117 | 119 | | |
118 | 120 | | |
119 | | - | |
120 | | - | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
| 77 | + | |
77 | 78 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | 79 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 80 | + | |
| 81 | + | |
98 | 82 | | |
99 | 83 | | |
100 | 84 | | |
101 | | - | |
102 | | - | |
| 85 | + | |
103 | 86 | | |
104 | 87 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | 88 | | |
110 | 89 | | |
111 | | - | |
| 90 | + | |
112 | 91 | | |
113 | 92 | | |
114 | 93 | | |
115 | | - | |
| 94 | + | |
116 | 95 | | |
117 | 96 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | 97 | | |
132 | 98 | | |
133 | | - | |
| 99 | + | |
134 | 100 | | |
135 | 101 | | |
136 | 102 | | |
137 | | - | |
| 103 | + | |
138 | 104 | | |
139 | 105 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | 106 | | |
150 | 107 | | |
151 | | - | |
| 108 | + | |
152 | 109 | | |
153 | 110 | | |
154 | 111 | | |
| |||
0 commit comments