Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:1kbgz Tributary Dirty Propagation

From Leeroopedia
Knowledge Sources
Domains Lazy_Evaluation, Incremental_Computation
Last Updated 2026-10-14 00:00 GMT

Overview

A mechanism for tracking which nodes in a computation graph need re-evaluation when an input changes, by propagating a "dirty" flag downstream from the changed node to all dependents.

Description

Dirty propagation is the incremental computation mechanism that makes lazy evaluation efficient across multiple evaluation cycles. When a node's value changes:

  1. The node itself is marked dirty (needs re-evaluation)
  2. All downstream nodes (transitive dependents) are recursively marked dirty
  3. On the next evaluation, only dirty nodes are re-computed; clean nodes return cached values

This solves the problem of knowing which parts of a computation graph are stale after an input change. Without dirty propagation, either the entire graph re-evaluates (wasteful) or the user must manually track dependencies (error-prone).

Key characteristics:

  • Change detection: Values are compared (with numeric tolerance) to determine if a change occurred.
  • Downward propagation: Dirty flags cascade from the changed node to all transitive descendants.
  • Lazy clearing: Dirty flags are cleared only when a node is actually re-evaluated.
  • Dynamic nodes: Nodes marked as dynamic always re-evaluate regardless of dirty state.

Usage

Use this principle when you need incremental recomputation in a graph: inputs change occasionally, and only the affected subgraph should re-evaluate. This is essential for interactive applications, parameter sweeps, and optimization loops.

Theoretical Basis

Dirty propagation is a form of incremental computation where the build system tracks dependencies and rebuilds only what is necessary.

# Abstract dirty propagation model (NOT real implementation)
def set_value(node, new_value):
    if value_changed(new_value, node.cached_value):
        mark_dirty(node)              # mark self
        for dep in node.downstream:
            mark_dirty(dep)           # propagate downstream
    node.cached_value = new_value

def evaluate(node):
    if not node.is_dirty and not node.is_dynamic:
        return node.cached_value
    result = node.func(*[evaluate(d) for d in node.upstream])
    node.cached_value = result
    node.is_dirty = False
    return result

The propagation follows the DAG's topological structure: a node is dirty if and only if it or any of its transitive upstream dependencies has changed.

dirty(n)⟺changed(n)∨⋁d∈upstream(n)dirty(d)

Related Pages

Implemented By

Uses Heuristics

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment