# Live variables

> Which values must a compiler keep at each block boundary? On a loop header that can enter its body or return a result, the header needs the guard, the value the body will read, and the result the exit will return. This workload computes those sets twice and measures how many blocks each schedule evaluates.

Which values must a compiler keep at each block boundary? On a loop header that can enter its body or return a result, the header needs the guard, the value the body will read, and the result the exit will return. This workload computes those sets twice and measures how many blocks each schedule evaluates.

## Result

> A backward worklist saves 510 of 768 block evaluations on a 256-block control-flow graph

## Modules

* [`knotkit/graph`](/modules/graph/): Provides breadth-first search, Dijkstra, topological order, and connected components over integer-vertex graphs, stored as adjacency lists, compressed sparse rows, or an adjacency matrix
* [`knotkit/bitset`](/modules/bitset/): Provides exact membership, cardinality, set algebra, and order statistics over unsigned 32-bit ids, in one flat bitmap or 65,536-id chunks
* [`knotkit/deque`](/modules/deque/): Queues elements at both ends in O(1) amortized time, over array and Float64Array ring buffers, with an optional fixed capacity that turns the queue into a sliding window

## Figures

* At 256 blocks, full sweeps evaluate 768 blocks and the predecessor worklist evaluates 258, saving 510 evaluations.
* Both schedules agree on every entry and exit set. Variables 0, 1, 2 are live on entry to the loop header.
* Both start with empty live sets and visit higher block IDs first. Only the worklist limits later visits to affected predecessors.

Hover or focus a chart for exact values. Drawn by [`demo.ts`](https://github.com/jkomyno/knotkit/blob/main/problems/live-variables/demo.ts) at build time, from the fixtures the benchmark uses; it reproduces the README figure.

## Reproduce

```bash
git clone https://github.com/jkomyno/knotkit.git && cd knotkit && bun install
bun run demo:problem:live-variables
```

[`problems/live-variables/README.md`](https://github.com/jkomyno/knotkit/blob/main/problems/live-variables/README.md) states the fixture, the seed, and the result table.
