Expand description
Compilation cache for TensorLogic expressions.
Provides two complementary caching mechanisms:
-
CompilationCache— A thread-safe, key-based cache that stores compiledEinsumGraphinstances keyed by a composite hash of expression structure, compilation configuration, and domain information. Designed for concurrent use. -
LruCompilationCache— A single-threaded LRU cache keyed byExprFingerprint(a structural content-address of an expression). Evicts the least-recently-used entry when capacity is exceeded. Designed for use inside aCachingCompilerwrapper.
§Choosing the right cache
| Scenario | Recommended type |
|---|---|
| Single-threaded compilation loop | LruCompilationCache / CachingCompiler |
| Multi-threaded compilation (shared) | CompilationCache |
| Batch compilation of related exprs | CachingCompiler::compile_batch |
§Example — LRU cache via CachingCompiler
use tensorlogic_compiler::cache::{CachingCompiler, CacheStats};
use tensorlogic_compiler::compile_to_einsum;
use tensorlogic_ir::{TLExpr, Term};
let mut compiler = CachingCompiler::new(64, |expr| {
compile_to_einsum(expr).map_err(|e| e.to_string())
});
let expr = TLExpr::pred("knows", vec![Term::var("x"), Term::var("y")]);
let _g1 = compiler.compile(&expr).expect("first compile");
let _g2 = compiler.compile(&expr).expect("second compile (cache hit)");
assert_eq!(compiler.cache_stats().hits, 1);
assert_eq!(compiler.cache_stats().misses, 1);Structs§
- Cache
Stats - Aggregate statistics for any compilation cache.
- Cached
Result - A cached compilation result stored in an
LruCompilationCache. - Caching
Compiler - Compilation
Cache - Thread-safe compilation cache for storing and retrieving compiled expressions.
- Expr
Fingerprint - A compact fingerprint of a
TLExprstructure (not values). - LruCompilation
Cache - LRU compilation cache with configurable capacity.