r/Protos • • 3h ago

How much unnecessary work happens inside a regular expression engine?

Regex performance is not just about the matching algorithm. Allocation, state tracking, Unicode processing and unnecessary text materialization can all contribute significant overhead.

The latest Regex optimization in Protos addresses several of these areas:

  • Indexed chunk storage instead of dense maps.
  • Reusable matcher workspaces.
  • Generation-based state deduplication.
  • More efficient character-set operations.
  • Direct span-based replacement and splitting.
  • Capture arrays copied only when their values change.

The prioritized Thompson matching algorithm and public API remain unchanged, and the implementation stays entirely within Protos.

All 141 Regex regression tests passed, along with the exhaustive CI pipeline.

An interesting question for regular expression engine implementations: how much optimization potential remains outside the matching algorithm itself?

Implementation: https://github.com/guillermomolina/protos/pull/1334

Repository: https://github.com/guillermomolina/protos

Website: https://protoslang.com

1 Upvotes

0 comments sorted by