Notebooks & Reactivity

Questions from Josh @jmp: I’m curious what approach you’ve taken to implement reactivity in marimo. Eg are dependencies computed statically or dynamically? How are side effects handled? What if someone doesn’t want a cell to rerun? Can they control execution in some way?
1 Reply
Myles Scolnick
Myles Scolnick13mo ago
@jmp let me know if you want me to dive deeper into any points: * reactivity is tracked using static analysis (traversing the AST). kinda like when Excel figured out what cells depend on each other * each cell tracks what variables is defines and it consumes. you can consider these inputs and outputs to a graph, so we have a DAG for all the cells. this is why you cannot redefine variables like you can in Jupyter (which is a bad practice we want to get rid of) * side-effects like mutating state (list.append) is not tracked. we want you to be as immutable as possible, so we can handle the updates for you. if you need to mutate state, you can use an advanced feature mo.state which can wrap any mutable state and still track changes. this is very similar to how React works under the hood if you have used the before * if you dont want to re-run a cell, there is a way to disable them in the UI. some more info about that here * what we want to control in terms of execution is making sure everything is up-to-date. otherwise there is hidden state and non-reproducible code. we also ensure the execution order is run topologically, instead of top-down. besides that, we only re-run what is necessary (smallest possible updates) on code/variable changes more details on reactivity here: https://docs.marimo.io/guides/reactivity.html