Understand Query Functions in Salsa
masterA query function is a user-provided function executed by Salsa to compute the value of a [derived query].
When writing query functions, keep the following assumptions in mind:
- Purity: Salsa assumes all query functions are 'pure' functions of their dependencies. If a function relies on state not tracked by Salsa, you must explicitly report an [untracked read].
- Side-effects: Salsa assumes functions have no important side-effects (e.g., sending network messages where the result must be observed).
- Re-execution: Because of these assumptions, Salsa only re-executes functions when it needs their return value and their dependencies have changed.