Installation
Basic usage
Loader
The loader pattern enables dynamic decision loading from any storage backend. Implement theZenDecisionLoaderCallback interface with a suspend fun load(key: String): JsonBuffer? method. Use ConcurrentHashMap to cache decisions for optimal performance.
Assets
Internal storage
Firebase Remote Config
Remote URL with caching
Remote URL with zip
Firebase Storage with zip
Coroutines
Evaluation functions aresuspend functions, integrating natively with Kotlin coroutines:
Error handling
Tracing
Enable tracing to inspect decision execution:Expression utilities
Evaluate ZEN expressions outside of a decision context:Performance note
The Android bindings use JNA (Java Native Access) for interoperability with the native Rust engine. This introduces some overhead compared to native Rust or direct bindings. We plan to revisit this when the FFM (Foreign Function & Memory) API becomes more widely adopted.
Best practices
Use.use {} for resource management. ZenEngine implements AutoCloseable to release native resources.
ZenEngine instance at application startup and reuse it for all evaluations.
Cache decisions persistently. Use internal storage or SharedPreferences to cache downloaded decisions for offline use.
Evaluate on background threads. Use Dispatchers.Default or Dispatchers.IO to avoid blocking the main thread.
Bundle fallback decisions. Include decisions in assets as fallback for first launch or network failures.