zombie-rs
A Rust implementation of the Zombie monad for memory-efficient lazy evaluation with automatic eviction and recomputation.
Core Idea: Trade computation time for memory — evict values when memory is tight, recompute on demand.
Quick Start
use *;
Note:
Runtime::init()initializes thread-local state. This is a Rust-specific design for thread safety.
Installation
[]
= "0.0.1"
Requires Rust nightly (edition 2024 features). Note: This requirement is temporary pending stabilization of used features.
Core API
// Create
let z = new;
// Access (recomputes if evicted)
let val = z.get;
z.with;
// Transform
let z2 = z.map;
let z3 = z.bind;
Key Concepts
Evictable vs Non-Evictable
// NOT evictable - RootContext
let root = new;
// Evictable - created via combinators
let evictable = root.map;
Memory Limit
let config = default
.with_memory_limit; // 100MB
init_with_config;
When to Use
Based on the Zombie paper:
| ✅ Good Use Cases | ❌ Poor Use Cases |
|---|---|
| Large intermediate values — Images, matrices, large data | Tiny values — Overhead exceeds benefit (< 1KB) |
| Huge input — Large images, GB-sized logs, huge projects | Need all values simultaneously |
| Low memory environments — WASM (2GB limit), embedded, GPU | High-frequency random access |
| Intermediate state — Time-travel debug, Jupyter, autodiff | Side effects — Must be pure/deterministic |
| Linear dependencies — Pipelines, streaming transforms | Extremely expensive recomputation |
Key insight: X% memory reduction with typically Y% run-time increase.
Extreme Optimization Showcase (v0.0.1)
Running a deep composition pipeline processing 8GB of vector data on a MacBook Air M4:
| Metric | Standard Rust | Zombie-rs (100MB Limit) | Impact |
|---|---|---|---|
| Peak Memory | ~8.2 GB | 104 MB | 98.7% Reduction |
| Execution Time | 1.8s | 2.1s | +16% Overhead |
Note: This is an extreme scenario designed to showcase eviction capabilities. Real-world overhead varies based on computation granularity. Tests run on v0.0.1.
Code Example
use *;
Benchmarking
# Note: `./benches.sh <ARGS>` is just a wrapper script for `cargo run --release -- <ARGS>`
# Quick benchmark
# Full benchmark with baseline comparison (500+ runs recommended)
# Save results as baseline
Metrics: CV (noise), Time (median), Peak (memory), Meta (overhead)
Data from zombie-rs v0.0.1; future versions may differ.
Additional Utilities (zombie_utils)
[]
= "0.0.1"
use *;
use *;
Documentation
- examples/ — Usage examples (basic → advanced)
- tests/ — Test cases and edge cases
- paper/ — Academic paper (Typst format)
- ARCHITECTURE_REVIEW.md — Internal architecture and algorithm details
Naming & Renaming
To provide a more modern and intuitive API, we have renamed core internal components from their original Sanskrit names (used in the C++ implementation) to English descriptors:
| New Name | Original Name | Meaning |
|---|---|---|
| Runtime | Trailokya | The global state manager |
| Timeline | Akasha | The context/tock tree |
| Zombie | Zombie | Values that "die" (evict) and "resurrect" (recompute) |
References
- Zombie Paper — Original LaTeX
- C++ Implementation
License
MIT