A framework for on-demand, incremental computation via memoization, inspired by Rust lang's salsa-rs/salsa.
- a memoization framework, with
- runtime dependency tracking, so that
- you can update some inputs and (performantly) automatically invalidate the affected caches.
It provides a framework for automating away the potential pitfalls of cache invalidation, by automatically detecting dependencies between parts of your code (
@derived functions), and using the detected dependency graph to propagate invalidations when facts about the world have changed.
julia> @declare_input x(rt)::Int (x, set_x!, delete_x!) julia> @derived function x_plus_one(rt) println("Running x_plus_one.") return x(rt) + 1 end x_plus_one (generic function with 1 method)
julia> rt = Runtime(); julia> set_x!(rt, 1) julia> x_plus_one(rt) Running x_plus_one. 2 julia> x_plus_one(rt) 2 julia> set_x!(rt, 10) julia> x_plus_one(rt) Running x_plus_one. 11
For maximum performance in deployed software, you can disable all runtime assertions and debug code by setting this environment variable before building Salsa:
Or, for slightly less peformance gain, you can toggle it at runtime via
We highly recommend this talk which motivates the need for incremental, demand driven computation, and for packages like Salsa:
Comparison with the Rust Salsa-rs framework
The underlying principles are very similar to, and inspired from that package: It can be hard to write correct incremental programs by hand, so we provide macros that make it easy by automatically tracking dependencies between computations.
If you are familiar with Salsa-rs, you'll see many things that are familiar, with slightly more generic names that are moved away from database-oriented naming:
- derived queries =>
- query group =>