Skip to content

Regex predicate DFAs are deserialized on every evaluation #426

Description

@zharinov

Problem

Regex predicates ((identifier =~ /foo.*/)) deserialize their DFA from module bytes on every evaluation, inside the VM's match loop:

crates/plotnik-vm/src/engine/vm.rs, evaluate_predicateplotnik_bytecode::deserialize_dfa(regex_bytes) per call.

A regex predicate inside a quantified pattern over a large file deserializes the same DFA thousands of times.

Approach

Deserialize once and reuse:

  • Simplest: a lazy per-regex-index cache on the VM (Vec<OnceCell<DFA>> sized to the regex table), built on first use per execution.
  • Better: deserialize zero-copy at Module load — the crate already ensures 64-byte alignment for embedded bytecode (include_query_aligned), and regex_automata DFAs support zero-copy deserialization from aligned bytes. This may be a lifetime exercise rather than a copy.

Acceptance

  • A trace/benchmark shows one deserialization per distinct regex per execution (or zero at exec time with the load-time approach).
  • No behavior change — existing predicate tests pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions