https://github.com/julia-vscode/salsa.jl
https://github.com/julia-vscode/salsa.jl
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/julia-vscode/salsa.jl
- Owner: julia-vscode
- License: mit
- Created: 2020-02-15T03:22:29.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-12T13:54:19.000Z (5 months ago)
- Last Synced: 2025-04-07T00:41:54.279Z (3 months ago)
- Language: Julia
- Homepage:
- Size: 237 KB
- Stars: 68
- Watchers: 6
- Forks: 3
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Salsa.jl
[](https://travis-ci.com/RelationalAI-oss/Salsa.jl)
A framework for on-demand, incremental computation via memoization, inspired by Rust lang's
[salsa-rs/salsa](https://github.com/salsa-rs/salsa).[⏯ Youtube | JuliaCon 2020 | Salsa.jl](https://youtu.be/0uzrH2Ee494)
## Description
Salsa is:
- 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.
## Usage
- `@derived`
- `@declare_input`
- `Runtime()````julia
julia> using Salsajulia> @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
julia> rt = Salsa.Runtime();julia> set_x!(rt, 1)
julia> x_plus_one(rt)
Running x_plus_one.
2julia> x_plus_one(rt)
2julia> set_x!(rt, 10)
julia> x_plus_one(rt)
Running x_plus_one.
11
```### Flags
For maximum performance in deployed software, you can disable all runtime assertions and debug code by setting this environment variable before building Salsa: `SALSA_STATIC_DEBUG=false`.
Or, for a slightly smaller performance gain, you can toggle it at runtime via `Salsa.Debug.disable_debug()`.
## Credits
This package was closely modeled on the Rust
[`salsa`](https://github.com/salsa-rs/salsa) framework, and takes heavy inspiration from
that framework and [adapton](http://adapton.org/).We highly recommend this talk which motivates the need for incremental, demand-driven
computation, and for packages like Salsa:
- [YouTube: Responsive compilers - Nicholas Matsakis - PLISS 2019](https://www.youtube.com/watch?v=N6b44kMS6OM&t=984s)### 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 similar, with
slightly more generic names that are moved away from database-oriented naming:
- **derived queries** => **`@derived` functions**
- **query group** => **`Runtime`**