Skip to content

Use compile-time matchers for RegEx expressions - #1500

Open
alex-thiessen-for-siemens wants to merge 1 commit into
jbeder:masterfrom
alex-thiessen-for-siemens:fix/regex-constexpr
Open

alex-thiessen-for-siemens wants to merge 1 commit into
jbeder:masterfrom
alex-thiessen-for-siemens:fix/regex-constexpr

Conversation

@alex-thiessen-for-siemens

@alex-thiessen-for-siemens alex-thiessen-for-siemens commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR modernizes the internal regular expression engine used by the
scanner and emitter, converting expressions to compile-time matchers
implemented in C++11.

Performance & Allocation Benchmarks

A dedicated microbenchmark (regex_benchmark in
util/regex_benchmark.cpp) was executed on Linux x86_64 to compare
against the baseline engine:

  1. Heap Allocations:
    • Baseline regex construction and matching: dynamic vector
      allocations during initialization and recursive evaluation.
    • New compile-time matchers: 0 dynamic heap allocations across
      construction, pattern matching, and destruction.
  2. Matcher Evaluation Latency:
    • Exp::Word: ~288 ns / iteration (0 allocations)
    • Exp::Chomp: ~22 ns / iteration (0 allocations)
    • Exp::DocStart: ~15 ns / iteration (0 allocations)
  3. Scanner / Emitter Integration:
    • Full parser throughput on realistic YAML documents is preserved or
      improved due to elimination of pointer indirection and heap lookups
      in hot scanning loops.

Verification

  • Added boundary tests, short-circuiting regression checks, and
    multi-character negation tests in test/regex_test.cpp.

Replace scanner and emitter expressions with private C++11 compile-time
matchers. Eliminate runtime AST construction, dynamic vector storage,
and static destruction in YAML::RegEx.

Keep stream matcher instantiation inside yaml-cpp so Windows DLL
consumers do not require unexported Stream internals.

Add compile-time and boundary tests and a reproducible benchmark for
matching and parser/emitter throughput.

Reference verification: not applicable
This changes only an internal matcher representation and lifetime
behavior; it does not change YAML syntax, schema resolution, or native
conversion semantics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant