Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

docs: lazy runtime (#1333)

Akshay Agrawalb14cfa1ad12e
diff --git a/README.md b/README.md
index 9520d574e0..427ac66c1a 100644
--- a/README.md
+++ b/README.md
@@ -63,7 +63,8 @@ automatically re-run with their latest values.
**Performant runtime.** marimo runs only those cells that need to be run by
statically analyzing your code. You can optionally disable expensive cells to
-prevent them from automatically running.
+prevent them from automatically running, or configure the runtime to be
+lazy and mark affected stales as stale instead of automatically running them.
**Batteries-included.** marimo comes with GitHub Copilot, Black code
formatting, HTML export, fast code completion, a [VS Code
diff --git a/docs/_static/css/custom.css b/docs/_static/css/custom.css
index 54bb2024d8..8a40b366c7 100644
--- a/docs/_static/css/custom.css
+++ b/docs/_static/css/custom.css
@@ -50,6 +50,10 @@ iframe.demo.large {
height: 600px;
}
+iframe.demo.xlarge {
+ height: 1200px;
+}
+
.highlight {
border-radius: 0.4rem;
}
diff --git a/docs/faq.md b/docs/faq.md
index 21e3baed09..5819b2ca9f 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -8,7 +8,9 @@
- [Is marimo a notebook or a library?](#faq-notebook-or-library)
- [What's the difference between a marimo notebook and a marimo app?](#faq-notebook-app)
- [How does marimo know what cells to run?](#faq-reactivity)
+ - [Does marimo slow my code down](#faq-overhead)
- [How do I prevent automatic execution from running expensive cells?](#faq-expensive)
+ - [How do I disable automatic execution?](#faq-lazy)
- [How do I use sliders and other interactive elements?](#faq-interactivity)
- [How do I add a submit button to UI elements?](#faq-form)
- [How do I write markdown?](#faq-markdown)
@@ -167,6 +169,14 @@ your cells. Each cell is a node in the graph across which global
variables "flow". Whenever a cell is run, either because you changed its
code or interacted with a UI element it reads, all its descendants run in turn.
+<a name="faq-overhead"></a>
+
+### Does marimo slow my code down?
+
+No, marimo doesn't slow your code down. marimo determines the dependencies
+among cells by reading your code, not running or tracing it, so there's
+zero runtime overhead.
+
<a name="faq-expensive"></a>
### How do I prevent automatic execution from running expensive cells?
@@ -187,6 +197,14 @@ intermediate computations (see our [best practices guide](guides/best_practices.
- Wrap UI elements in a [form](api/inputs/form.md#marimo.ui.form).
- Use [`mo.stop`](api/control_flow.md#marimo.stop) to conditionally stop
execution of a cell and its descendants.
+- Disable automatic execution in the [runtime configuration](/guides/runtime_configuration.md).
+
+<a name="faq-lazy"></a>
+
+### How do I disable automatic execution?
+
+You can disable automatic execution through the notebook runtime settings;
+see the [guide on runtime configuration](/guides/runtime_configuration.md).
<a name="faq-interactivity"></a>
diff --git a/docs/guides/coming_from_jupyter.md b/docs/guides/coming_from_jupyter.md
index 7493196152..fbec63d72f 100644
--- a/docs/guides/coming_from_jupyter.md
+++ b/docs/guides/coming_from_jupyter.md
@@ -3,5 +3,5 @@
If you're coming from Jupyter, this guide will help you get started
with marimo. Fun fact: the guide is itself a marimo notebook!
-<iframe src="https://marimo.app/l/z0aerp?embed=true" width="100%" height=1200 class="demo" frameBorder="0">
+<iframe src="https://marimo.app/l/z0aerp?embed=true" class="demo xlarge" frameBorder="0">
</iframe>
diff --git a/docs/guides/editor_features.md b/docs/guides/editor_features.md
index e5a64aecaa..ea8f1ac38b 100644
--- a/docs/guides/editor_features.md
+++ b/docs/guides/editor_features.md
@@ -83,21 +83,8 @@ _Missing a command? File a
## Module autoreloading
-Enable module autoreloading via the settings icon (top right). When enabled,
-when Python modules that your notebook imports are modified, marimo reloads
-those modifications so you can use the latest version of your code. This works
-recursively, meaning that marimo tracks modifications for modules imported
-by your notebook's imported modules too.
-
-Autoreloading comes in two types:
-
-- "lazy": automatically marks cells affected by module
- modifications as stale, letting you know which cells need to be re-run.
-- "autorun": automatically re-runs cells affected by module modification.
-
-**Why autoreload?** Autoreloading enables a workflow that many developers find
-productive: develop complex logic in Python modules, and use the marimo
-notebook as a DAG or main script that orchestrates your logic.
+Enable module autoreloading via the settings icon (top right). Learn more
+in the [runtime configuration guide](/guides/runtime_configuration.md#on-module-change).
## Export to static HTML
diff --git a/docs/guides/index.md b/docs/guides/index.md
index d13b6eb0fb..29dfd4e97f 100644
--- a/docs/guides/index.md
+++ b/docs/guides/index.md
@@ -8,6 +8,7 @@
overview
reactivity
interactivity
+ runtime_configuration
coming_from_jupyter
outputs
editor_features
@@ -33,6 +34,7 @@ These guides cover marimo's core concepts.
| {doc}`reactivity` | How reactive execution works |
| {doc}`interactivity` | Using interactive UI elements |
| {doc}`coming_from_jupyter` | marimo for Jupyter users |
+| {doc}`runtime_configuration` | Configure how and when cells are run |
| {doc}`outputs` | Markdown, plots, and other visual outputs |
| {doc}`editor_features` | View variables, cell dependencies, errors, and more |
| {doc}`dataframes` | Working with dataframes |
diff --git a/docs/guides/overview.md b/docs/guides/overview.md
index 45951c3aa7..0d974782d1 100644
--- a/docs/guides/overview.md
+++ b/docs/guides/overview.md
@@ -27,6 +27,14 @@ variables defined by that cell._ This is reactive execution.
</figure>
</div>
+```{admonition} Lazy evaluation
+:class: tip
+
+If you don't want cells to run automatically, the runtime can be
+configured to be lazy, only running cells when you ask for them to be run and
+marking affected cells as stale. Learn more in the
+[runtime configuration guide](/guides/runtime_configuration.md)
+```
**Execution order.**
The order of cells on the page has no bearing on the order cells are
diff --git a/docs/guides/reactivity.md b/docs/guides/reactivity.md
index dce75f3d27..cef5475cda 100644
--- a/docs/guides/reactivity.md
+++ b/docs/guides/reactivity.md
@@ -16,6 +16,15 @@ When a cell is run, marimo automatically runs all other cells that
**reference** any of the global variables it **defines**.
```
+```{admonition} Lazy evaluation
+:class: note
+
+The runtime can be configured to be lazy, only running cells when you ask for
+them to be run and marking affected cells as stale, instead of automatically
+running them. Learn more in the
+[runtime configuration guide](/guides/runtime_configuration.md)
+```
+
## References and definitions
A marimo notebook is a DAG where nodes are cells and edges are data
dependencies. marimo creates this graph by statically analyzing each cell
@@ -156,3 +165,13 @@ disabled, marimo will automatically run it.
automatically.</figcaption>
</figure>
</div>
+
+```{admonition} Lazy evaluation
+:class: note
+
+If you prefer, you can configure the runtime to be lazy, only running cells
+when you ask for them to be run and marking affected cells as stale. When
+your notebook has expensive cells, choosing lazy execution can be more
+convenient than manually disabling and enabling cell. Learn more
+in the [runtime configuration guide](/guides/runtime_configuration.md)
+```
diff --git a/docs/guides/runtime_configuration.md b/docs/guides/runtime_configuration.md
new file mode 100644
index 0000000000..7721a81805
--- /dev/null
+++ b/docs/guides/runtime_configuration.md
@@ -0,0 +1,49 @@
+# Runtime configuration
+
+Through the notebook settings menu, you can configure how and when marimo
+runs cells.
+
+## On startup
+
+By default, marimo runs notebooks automatically on startup. Disable
+this by unchecking "Autorun on startup".
+
+_When sharing a notebook as an app with `marimo run`, this setting has
+no effect._
+
+## On cell change
+By default, when a cell is run or a UI element is interacted with, marimo
+automatically runs cells that reference any of its variables. **You can disable
+automatic execution of cell's descendants in the notebook settings menu by
+setting `"On cell change"` to `"lazy"`.**
+
+When the runtime is lazy, running a cell marks affected cells as stale but
+doesn't automatically run them. Lazy evaluation means cells are only run when
+their outputs are needed. If you run a cell that has stale ancestors, those
+ancestors will also run to make sure your cell doesn't use stale inputs. You
+can always click the notebook run button or use the keyboard shortcut to run
+all stale cells.
+
+**When should I use lazy evaluation?** Choosing the lazy runtime can be helpful
+when working on notebooks with expensive cells.
+
+_When sharing a notebook as an app with `marimo run`, this setting has
+no effect._
+
+## On module change
+
+Enable module autoreloading via the settings icon (top right). When enabled,
+when Python modules that your notebook imports are modified, marimo reloads
+those modifications so you can use the latest version of your code. This works
+recursively, meaning that marimo tracks modifications for modules imported
+by your notebook's imported modules too.
+
+Autoreloading comes in two types:
+
+- "lazy": automatically marks cells affected by module
+ modifications as stale, letting you know which cells need to be re-run.
+- "autorun": automatically re-runs cells affected by module modification.
+
+**Why autoreload?** Autoreloading enables a workflow that many developers find
+productive: develop complex logic in Python modules, and use the marimo
+notebook as a DAG or main script that orchestrates your logic.