polix.optimized.evaluator
Optimized policy evaluator using pre-computed templates.
Creates fast evaluation functions that avoid AST traversal by pre-computing residual templates at compile time. This is a cross-platform (CLJ/CLJS) implementation using Clojure closures.
On the JVM, Tier 3 (T3) bytecode compilation is available for additional performance when all operators are built-in.
bytecode-eligible?
(bytecode-eligible? constraint-set)Returns true if the constraint set can be compiled to JVM bytecode.
Bytecode compilation (T3) requires: - No complex nodes (quantifiers, let bindings) - All operators are built-in (no custom operators)
compile-policy
(compile-policy constraint-set)(compile-policy constraint-set opts)Compiles a constraint set to an optimized evaluator.
Takes a constraint set (output of compiler/normalize-and-merge) and optional options map. Returns an ICompiledPolicy that can be called as a function.
Options: - :tier - force a specific tier (:t0, :t1, :t2, or :t3 on JVM) - :fallback - fallback evaluator for Tier 1 (required if custom ops present) - :bytecode - on JVM, set to false to disable bytecode compilation (default true)
Returns a CompiledPolicy record implementing IFn.
Tier selection (highest to lowest performance): - T3: JVM bytecode (JVM only, requires all built-in operators) - T2: Optimized Clojure closures - T1: Guarded closures with version check - T0: Interpreted fallback
create-tier1-evaluator
(create-tier1-evaluator constraint-set tier0-evaluator)Creates a Tier 1 (guarded) policy evaluator.
Takes a constraint set and returns a function that evaluates documents. Includes version guards for custom operators with fallback to Tier 0.
create-tier2-evaluator
(create-tier2-evaluator constraint-set)Creates a Tier 2 (optimized) policy evaluator.
Takes a constraint set and returns a function that evaluates documents. All operators must be built-in for Tier 2 compilation.
Pre-computes open residuals and per-constraint conflict makers at creation time, so evaluation only needs to: 1. Look up document values 2. Check constraints in a tight loop 3. Return pre-computed residuals on failure
ICompiledPolicy
protocol
Protocol for compiled policy evaluators.
members
compilation-tier
(compilation-tier this)Returns the compilation tier (:t0, :t1, or :t2).
compiled-version
(compiled-version this)Returns the registry version at compile time.
evaluate
(evaluate this document)Evaluates the policy against a document. Returns {} for satisfied, {:path constraints} for open/conflict.
optimized-eligible?
(optimized-eligible? constraint-set)Returns true if the constraint set is eligible for optimized evaluation.
A constraint set is eligible if: - It has no complex (non-constraint) nodes - All operators are either built-in or have a fallback evaluator