Skip to content

feat(optimize): add literal_runtime_dense dispatch tier#24

Merged
sentomk merged 4 commits intomainfrom
feat/on-compile-time-accel
Apr 30, 2026
Merged

feat(optimize): add literal_runtime_dense dispatch tier#24
sentomk merged 4 commits intomainfrom
feat/on-compile-time-accel

Conversation

@sentomk
Copy link
Copy Markdown
Owner

@sentomk sentomk commented Apr 30, 2026

Summary

Add a literal_runtime_dense dispatch tier that sits between static_literal_dense (density >= 1/4) and literal_linear (O(n) fallback). By relaxing the density threshold to 1/8, sparse literal patterns (e.g. 10 cases spanning 0-100) get O(1) array dispatch instead of linear scan. No DSL or public API surface changes.

Changes

Core (optimize.hpp, eval.hpp)

  • New dispatch constants: k_runtime_literal_dense_dispatch_max_cases=256, _max_span=512, _max_density=8, _min_cases=4
  • is_runtime_literal_dense_dispatch_enabled trait
  • static_literal_dispatch_metadata gains use_runtime_dense_table field
  • case_sequence_ir / lowering_analysis export can_use_runtime_literal_dense_dispatch
  • New literal_runtime_dense_dispatch_plan struct, dispatch_plan_for_kind specialization
  • dispatch_plan_selector priority: static_dense -> runtime_dense -> literal_linear
  • eval_cases_with_dispatch_plan routes runtime_dense to the same eval_cases_impl_static_literal_dispatch evaluator

Benchmarks (bench/)

  • Runtime bench suite with 15 sparse literal values (density ~0.15): PatterniaPipe/IfElse/Switch_LiteralMatchRDense (3 benchmarks)
  • Compile-time TU ct_bench_lit_rdense.cpp (constexpr + static_assert)

Tests

  • 19 runtime benchmarks registered (was 16)
  • 8 compile-time TU targets compile cleanly (was 7)

Checklist

  • Tests added or updated when behavior changed
  • Documentation updated when public API or behavior changed
  • Commit messages follow CONTRIBUTING.md
  • PR targets main and passes required CI

sentomk added 2 commits April 30, 2026 20:19
Problem
- Literal patterns with density below 1/4 fell back to O(n) linear scan.
- An intermediate tier with relaxed density (1/8) can provide O(1) array
  dispatch for patterns like 10 cases spanning 0-100.

Implementation
- Added k_runtime_literal_dense_dispatch_max_cases=256 / _max_span=512 /
  _max_density=8 / _min_cases=4 constants.
- Added is_runtime_literal_dense_dispatch_enabled trait.
- Added use_runtime_dense_table field to static_literal_dispatch_metadata.
- Added can_use_runtime_literal_dense_dispatch to case_sequence_ir and
  lowering_analysis.
- New literal_runtime_dense_dispatch_plan struct and dispatch_plan_for_kind
  specialization.
- Updated dispatch_plan_selector priority: static_dense -> runtime_dense
  -> literal_linear.
- Extended eval_cases_with_dispatch_plan to route runtime_dense plans to
  the same eval_cases_impl_static_literal_dispatch evaluator.

Tests
- Added runtime bench suite: 15 sparse literal values (density ~0.15)
  comparing PatterniaPipe / IfElse / Switch.
- Added compile-time TU ct_bench_lit_rdense.cpp exercising the tier at
  compile time via constexpr + static_assert.

Notes
- No DSL or public API surface changes.
@sentomk sentomk force-pushed the feat/on-compile-time-accel branch from 6eb65d2 to 8a35432 Compare April 30, 2026 17:17
@sentomk sentomk changed the title feat: P1-C literal_runtime_dense dispatch tier feat(optimize): add literal_runtime_dense dispatch tier Apr 30, 2026
@sentomk sentomk merged commit d275c5d into main Apr 30, 2026
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