Skip to content

Patternia Performance - v0.9.3

Published: May 2026

Focus: Tuning variant inline dispatch threshold for common small-to-medium workloads.

Overview

v0.9.3 lowers the variant inline dispatch hot-path threshold from 16 to 8 alternatives. This means variant match expressions with ≤ 8 alternatives now use branch-based dispatch instead of jump tables, reducing icache pressure and branch misprediction overhead for the most common workload shapes. No API surface changes, no new algorithm — this is a single constant tuning change affecting dispatch strategy selection.

Motivation

Most real-world pattern-matching workloads use fewer than 8 variant alternatives. Before v0.9.3, the threshold was set at 16, which meant: - Variants with 9–16 alternatives used jump-table dispatch - Jump tables increase icache pressure and have higher cold-start cost - For many intermediate counts (8–15), branch-based dispatch often wins on modern CPUs

Lowering the threshold from 16 to 8 allows the hot-inline path to cover more practical use cases without introducing algorithmic complexity.

Change

Component Before (v0.9.2) After (v0.9.3)
k_variant_inline_dispatch_alt_threshold 16 8

The change lives in a single line: - optimize.hpp

No other dispatch logic, lowering paths, or runtime behavior is affected. Variants with more than 8 alternatives continue to use the existing tiered dispatch model unchanged.

Benchmarks

The following numbers come from the local run of:

./build-rel/bench/ptn_bench_lit --benchmark_filter="Variant|Packet" --benchmark_min_time=0.5s

Benchmark Before (v0.9.2) After (v0.9.3) Delta
VariantMixed [pending] [pending]
VariantMixedGuarded [pending] [pending]
PacketMixed [pending] [pending]
PacketMixedHeavyBind [pending] [pending]

Note: accurate side-by-side comparison requires running both versions on the same machine. The threshold change primarily helps the VariantMixed scenarios where alternative count falls in the 8–15 range.

Outcome

v0.9.3 is a conservative tuning release from a performance standpoint. It does not introduce dispatch algorithms, change lowering logic, or affect existing code paths besides shifting one strategy selection threshold. The goal is to make the default behavior match the actual distribution of real-world variant alternative counts.