# What things cost


These are measurements, not promises: they come from the machines effects was built on, at 1080p. They are here so you can estimate a render before starting one, and know which choices are cheap and which are not.

## Why the pipeline is short

A browser-based renderer draws a frame by loading a page in headless Chrome, running style, layout and paint, taking a screenshot, encoding that as an image, and handing the image to a video encoder that decodes it again. That happens once per frame, in a process built to be an interactive browser.

effects compiles your project into a shared library. Each worker thread owns a Skia raster surface and an encoder process. For every frame it calls your scenes, which call Skia, and writes the surface's raw pixels into the encoder's pipe. There is no page, no screenshot and no intermediate image file.

## Frame times

On a 16-thread laptop, one thread, 1920×1080:

| What is drawn | Time |
| --- | --- |
| Interface elements: text, rects, layers | about 2 ms a frame |
| Each full-screen pass (backdrop gradient, vignette, grain) | about 5 ms |
| A product spot with backdrop, vignette and grain on | about 32 ms on average |
| Glow (it is Skia's own blur) | about 20 ms |
| A post filter that reads each pixel three times | about 50 ms |
| A full-screen shader through `shader_scaled` at a third or half resolution | 0.1 to 0.5 s |
| A full-screen field of warped noise or a raymarched body at full resolution | about 2 s |

In the editor the same frames are drawn on the GPU: about 1 ms for the product spot.

## Render times

| Film | Machine | Time |
| --- | --- | --- |
| 12.4 s product spot, 60 fps (744 frames) | 16-thread laptop, x264 | about 20 s |
| 30.6 s showreel, 60 fps, shaders and footage | 16-thread laptop, x264 | 50 s |
| The same showreel | 24 threads, NVENC on a Quadro RTX 4000 | 22 s |
| 48.6 s edit, 30 fps, footage on every frame | 16-thread laptop, x264 | 62 s, peaking at about 15 GB |
| The same edit | 24 threads, NVENC | 22 to 25 s (35 s with x264 there) |
| 7 s of type, 60 fps (420 frames) | 8 cores, 5 workers, x264 | 6.5 s |
| fable: 60 s, 60 fps, mostly full-screen shaders | 8 cores, x264 | about 13 min |

For films made of interface, type and footage, encoding is the bottleneck, not drawing: x264 costs about 50 ms of CPU per frame, NVENC about 15 ms (most of that is the conversion to YUV, which stays on the CPU so both encoders tag and convert colors the same way).

Compiling a project takes about 0.4 s unoptimized (what the editor and `still` use) and about 3 s with `-o:speed` (what `render` uses).

## The slow part: shaders on the CPU

Final renders rasterize on the CPU, and SkSL on the CPU is the one expensive thing in the library. fable is the honest example: a minute of full-screen shaders takes thirteen minutes on eight cores, while a minute of interface and type would take well under one.

What to do about it:

- **Draw it small.** [`shader_scaled`](/docs/shade/) renders a shader at a fraction of the resolution and scales it up. Smooth fields (nebulae, gradients, noise) lose nothing at a third.
- **Bake what does not move.** [`bake`](/docs/draw/) renders a static layer once and reuses the image on every frame and thread.
- **Give layers bounds.** A group that blurs, fades or filters needs a layer; with `Xf.bounds` the layer is as large as its contents instead of as large as the frame. See [groups](/docs/group/).
- **Prefer glow to a hand-written bloom.** `Xf.glow` uses Skia's blur, which is far cheaper than a blur written in SkSL.
- **Measure.** `effects bench <project>` prints the average and the worst frame time. The worst frame tells you where to look.

## Memory

Each render worker has its own encoder and up to two footage decoders: about 1 GB at 1080p. The default number of workers is the number of cores, capped at what 70% of the available memory allows. `--workers n` sets it by hand.

## Encoder settings

`render` uses quality 18 for both encoders (x264's CRF, NVENC's constant QP): the same quality within about 1 dB, with NVENC files about 15% larger. `--encoder auto`, the default, uses NVENC when a test encode succeeds and x264 otherwise. A chunk whose NVENC session fails is drawn again and encoded with x264, so the render still finishes.

Near-black films with slow gradients need more bits than the default gives them, or the encoder puts back the banding that dithering removed. Use `--crf 16 --tune grain` for those.
