Skip to content

feat: dirty-flag rule skip, mode-aware pruning, batch fact setter, condition cache#8

Merged
tbitcs merged 1 commit into
mainfrom
orchestrator/optim
Jun 2, 2026
Merged

feat: dirty-flag rule skip, mode-aware pruning, batch fact setter, condition cache#8
tbitcs merged 1 commit into
mainfrom
orchestrator/optim

Conversation

@tbitcs
Copy link
Copy Markdown
Contributor

@tbitcs tbitcs commented Jun 2, 2026

Performance Optimizations

Add four performance optimizations to the arbiter engine:

1. Dirty-flag rule skip (CONFIG_ARBITER_DIRTY_SKIP)

  • Track which facts changed via uint64_t dirty_mask in snapshot
  • Compute per-rule dependency bitmask at compile time
  • Skip rule evaluation when no dependent facts changed
  • Emit ARBITER_MODEL_RULE_DEPS in generated header
  • Default on for standard/full profiles, off for nano/micro

2. Mode-aware rule pruning

  • Add required_mode field to ARBITER_rule_def
  • Compiler detects mode_guard rules with mode equality checks
  • Engine skips rules whose required_mode != current_mode
  • UINT16_MAX sentinel means evaluate in any mode

3. Batch fact setter (ARBITER_set_facts)

  • Validate context once, then loop setting each fact
  • Returns ARBITER_OK or first error encountered
  • More efficient than N individual ARBITER_set_i32 calls

4. Condition result cache (CONFIG_ARBITER_COND_CACHE)

  • 8-entry cache in eval loop for repeated condition checks
  • Keyed by (fact_id, op, value) tuple
  • Reset each eval cycle
  • Default on

Tests

All 141 tests pass, 1 skipped (golden vectors placeholder).


Conversation: https://app.warp.dev/conversation/cbbf5a9b-9163-44ac-8a72-ca91f2f49f74
Run: https://oz.warp.dev/runs/019e8993-e9ad-7e1b-b02b-d75ab0d24caf
This PR was generated with Oz.

…ndition cache

Add four performance optimizations to the arbiter engine:

1. Dirty-flag rule skip (CONFIG_ARBITER_DIRTY_SKIP):
   - Track which facts changed via uint64_t dirty_mask in snapshot
   - Compute per-rule dependency bitmask at compile time
   - Skip rule evaluation when no dependent facts changed
   - Emit ARBITER_MODEL_RULE_DEPS in generated header

2. Mode-aware rule pruning:
   - Add required_mode field to ARBITER_rule_def
   - Compiler detects mode_guard rules with mode equality checks
   - Engine skips rules whose required_mode != current_mode
   - UINT16_MAX sentinel means 'evaluate in any mode'

3. Batch fact setter (ARBITER_set_facts):
   - Validate context once, then loop setting each fact
   - Returns ARBITER_OK or first error encountered
   - More efficient than N individual ARBITER_set_i32 calls

4. Condition result cache (CONFIG_ARBITER_COND_CACHE):
   - 8-entry cache in eval loop for repeated condition checks
   - Keyed by (fact_id, op, value) tuple
   - Reset each eval cycle
   - Helps when multiple rules test the same condition

All existing tests pass (141 passed, 1 skipped).

Co-Authored-By: Oz <oz-agent@warp.dev>
@tbitcs tbitcs merged commit cee66aa into main Jun 2, 2026
2 of 7 checks passed
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