Skip to main content

Quick Wins

Enable Caching

Cache expressions and paths (enabled by default)

Reuse Engine

Create once, use many times

Order Rules

Put fastest checks first

Batch Evaluate

Evaluate multiple rules at once

Caching

Expression Cache

Caches evaluated expressions for repeated use.
Benefits:
  • ✅ 10-20x faster for repeated rules
  • ✅ Automatic LRU eviction
  • ✅ Memory efficient
When to disable:
  • Highly dynamic rules
  • Memory constraints
  • Rules evaluated once

Path Cache

Caches path resolutions.

Rule Ordering

Put fastest checks first to fail fast.

Performance Hierarchy

  1. Fastest: Simple comparisons (eq, neq, gt, lt)
  2. Fast: Array checks (in, notIn)
  3. Medium: String operations (contains, startsWith)
  4. Slow: Regex patterns (regex)
  5. Slowest: State changes (changed, increased)

Bad vs Good


Reuse Engine

Create once, reuse everywhere.

Batch Operations

Use StatefulRuleEngine.evaluateBatch() for multiple rules.
Benefits:
  • Single context preparation
  • Shared path resolutions
  • Better cache utilization

Minimize Depth

Flatten nested rules when possible.

Monitoring

Get Metrics

Cache Stats


Benchmarking


Real-World Optimization


Best Practices


Performance Checklist

  • Cache enabled
  • Reusing engine instance
  • Fast checks first in and rules
  • Slow checks last
  • Using batch operations
  • Monitoring metrics
  • Rules flattened (not deeply nested)
  • Clear cache when data schema changes

RuleEngine API

Metrics and caching methods

Operators

Operator performance characteristics