Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Content-Addressed Caching for Reactive Notebooks

A System for Cell-Level Cache Reuse in marimo

Authors
Affiliations
marimo
marimo
marimo

Abstract

We describe a caching mechanism that lets reactive notebooks restart without re-running their expensive cells. The mechanism is built into marimo, a reactive Python notebook that models the notebook as a dataflow graph. Each cell’s cached result is identified by a key built from fingerprints (hashes) of the cell’s code and inputs: an input whose bytes are accessible is hashed directly, and any other input is represented by the key of the cell that produced it, computed the same way. Because each cell’s key folds in the keys of the cells it depends on, editing one cell invalidates the cached results of exactly the cells downstream of it. Cached values are stored on disk and loaded only when accessed, so they can be reused across independent runs of the same notebook. They are also bundled into marimo’s static export, a standalone web page (HTML) that runs the notebook through WebAssembly (WASM), so readers whose only Python runtime is a browser can open a notebook with its expensive results and trained models already computed. In microbenchmarks over payloads of varying size, a marimo cache hit is comparable to widely used Python caching libraries, with a speedup on certain hardware, while asking almost nothing of the user.

Read it your way

The one-figure version

The cache key dispatch (left) and the derivation over a full cell (right): the same parse that schedules a cell yields its cache key.

The cache key dispatch (left) and the derivation over a full cell (right): the same parse that schedules a cell yields its cache key.