# Proxies, the cache and bakes

The working loop aims at "one frame at proxy resolution in under a second". Four mechanisms support that aim.

## Evaluation proxies

Evaluation runs at 1/1, 1/2, 1/4 or 1/8. The default factor comes from the comp's resolution, chosen so that the long edge gets close to `proxy.longEdge` (default 960 px). For 4K it is 1/4, for HD 1/2. `--proxy <1|2|4|8>` sets it explicitly.

`probe`, `preview`, `stats`, `bench` and the review window evaluate on proxies. Only `render --out` runs at full resolution by default.

## Source proxies

If a 4K image sequence is read at full resolution and scaled down every time, reading takes up most of the loop. `lamino proxy build <comp>` makes scaled-down copies of the footage the comp reads (by default 1/4, half float, DWAA-compressed EXR) under `.lamino/proxy/`. From then on, proxy evaluation reads these.

- One is made for each choice of layer and channels that a colour `read` uses, so it works for multi-layer EXRs too.
- It is used only when the hash of that frame has been verified in the lock. When the footage is replaced, the old proxy is not read.
- Data layers read with `aov` do not use source proxies.

The default compression `dwaa` is lossy, so source proxy pixels do not match the original values exactly. When you need exact values, set `proxy.compression` in `lamino.jsonc` to `zip`.

## The cache

Node outputs are cached in RAM and on disk.

| Tier | Location | Limit |
| --- | --- | --- |
| RAM | Inside the process. Shared by every comp | `physical RAM × cache.ramFraction` (default 0.5), capped by `cache.ramGib` when that is set |
| Disk | `cache.dir`. Defaults to `.lamino/cache/` in each shot | `cache.diskGib`. The default 0 means unlimited |

The cache key is built from the node type and its implementation version, the parameters, the input keys, the frame, the proxy factor, the region, the footage hashes, the colour settings and the backend. Because of that, you normally never need to clear the cache by hand. `--no-disk-cache` turns the disk cache off, and `--cache-dir` moves it.

The review window also has its own playback cache of 8-bit display frames (`review.displayCacheGib`; omitted, a quarter of the memory of the window's device), separate from this one.

## Bakes

Wrap a subgraph that is heavy even on proxies in `bake(node, "name")`. Render that node once at full resolution and the result stays in `.lamino/bake/`. From then on, both proxy evaluation and downstream nodes read the baked result.

The bake key is set by the subgraph and the content of its footage. It does not depend on the proxy factor or the backend. Changing an upstream parameter, or replacing even one frame of the footage, invalidates the bake.

## Cost budgets

Slowness is watched against limits. The values are under `limits` in `lamino.jsonc`.

| Key | Default | When exceeded |
| --- | --- | --- |
| `limits.proxyFrameMs` | 1000 ms | Target for one proxy frame. A node over half of it gets `L_SLOW_NODE` |
| `limits.nodeMs` | 500 ms | Budget for one node at proxy resolution. `E_COST_BUDGET` |
| `limits.frameMs` | 30000 ms | Limit for one frame. `E_RESOURCE_LIMIT` |
| `limits.gpuMb` | automatic | GPU memory budget. `E_RESOURCE_LIMIT`. Omitted, it is 75% of the video memory the OS lets the process use |

`E_COST_BUDGET` is not a signal to raise the limit. Make that element outside and read it as footage, or bake it with `bake()`. When a read node exceeds the budget, do one of these: build source proxies, reduce the number of EXR parts, or use a lighter compression.

The commands that find what is slow do not stop when a budget is exceeded. They report everything as warnings (`L_COST_BUDGET`, `L_FRAME_BUDGET`).

| Command | What it tells you |
| --- | --- |
| `lamino stats <comp>` | Evaluation time and cache hit rate per node, VRAM, and time per stage (decode, colour conversion, transfer, evaluation, readback, encode) |
| `lamino bench <comp> --frames 1001-1010` | Time per proxy frame, and fps |
| `lamino render ... --trace trace.json` | A trace you can open in Perfetto |

The engine decides how many frames a render evaluates at once (several on a hardware GPU, 1 on `cpu` and `gpu-software`). `--workers N` sets it explicitly.
