Skip to content

· 5 min read

The runway won’t wait for frame seven

A couture show has two customers for each camera frame. The archive wants every stitch. The backstage monitor wants whatever just happened. Jai and Goose put a very different price on that handoff.

A model in a pleated red coat turns on top of a film camera.
Illustration generated with GPT Image

Halfway down the runway, the model turns. For an instant you can see the green silk inside her red coat. The photographer wants that instant on disk. Backstage, the dresser is watching the monitor to see when the model turns back. A beautiful picture delivered late is a perfectly good photograph and a lousy cue.

Suppose we’re building the camera rig. We can give recording and preview their own workers. The interesting decision comes a few milliseconds later, when the camera hands us a new picture and both workers are busy. Here’s the same turn played through two possible monitors. Move the clock and watch the coat.

Oldest waiting

Frame 3 · 55 ms old

Newest waiting

Frame 6 · 25 ms old

Eight exposures, 10 ms apart. Both monitors take 25 ms to render a photo. The camera wins ties. Runway studies generated with GPT Image.

At 75 ms the left screen shows frame three, exposed 55 ms ago. The right shows frame six, just 25 ms old. Both workers finished exactly three jobs. The right one got closer to live by throwing away pictures it hadn’t started. That’s a decision I’d happily let the monitor make. Imagine finding out afterward that the same decision applied to the photographer’s negatives.

In Jai, hand over the address#

Ivo Balbaert’s little Jai thread-group example has an appealingly direct answer to “where does the result go?” The caller makes an array of work records and queues a pointer to each one. A worker writes the answer into the record. The caller collects completed pointers and reads the answers in place. The example enables work stealing. An idle thread can take a waiting job, so the caller collects completed records without having to predict which thread will finish each one. Balbaert’s Jai example.

Recorder jobsourcePreview jobsourceCapture slot 2exposure: 7

In the proposed camera rig, recorder and preview jobs point to the same captured exposure.

  • Recorder job: source points to Capture slot 2
  • Preview job: source points to Capture slot 2
  • Capture slot 2: exposure: 7
Two jobs can read exposure seven from one slot. The camera must wait for both readers before writing another exposure there.

I’d use that trick for our big images. Put the pixels in a fixed pool, give each reader its own job record, and let them read the same bytes. Queuing an address is cheap. Knowing when you can reuse that address is where you earn it. Say the recorder finishes first and releases slot two. If the camera fills it while the preview worker is halfway down the image, you can get the shoulders of one look and the hem of the next.

I’d put one coordinator in charge of recycling slots. It records which readers still hold each exposure. Replacing a waiting preview returns its claim immediately. Replacing one already being read has to wait for the worker’s completion. Give every completion a slot number and an exposure number, so a duplicate receipt for seven can’t release seventeen. Those are rules for our rig. The thread group reports which jobs finished. The coordinator knows which exposure each one held.

Goose will send the whole swatch#

Wouter van Oortmerssen’s Goose compiles a worker and its callees as a separate program with its own data stacks. A typed queue carries a copy of a value. In the author’s Mandelbrot renderer, a finished row travels as a row number followed by the actual pixels. The receiver can put it in the right place even if the workers finish out of order. A pointer back into a worker’s scratch space couldn’t make that trip. Goose’s threaded renderer.

3840 × 216031.64 MiB
960 × 5401.98 MiB
A full-size RGBA frame contains sixteen times as many bytes as the preview.
3840 × 216031.64 MiB
960 × 5401.98 MiB
Pixel payload per exposure at four bytes per pixel. Both sizes assume tightly packed rows.

Once the queue has copied the bytes, the preview worker can take as long as it likes without holding up that capture slot. At the larger size, one copy per exposure at 100 exposures a second means 3.32 GB of pixel payload per second, before the receiver takes its copy. That makes me want the preview scaler close to capture. Send the small image across. I’d measure the scaler on the capture path first. If shrinking a picture takes longer than the gap between exposures, the camera needs a scaler of its own or a separate worker with room to buffer the burst.

There’s a catch in the obvious next line of code. Goose lets me limit the preview queue to one message. I tried filling it with frame seven, then offering frame eight before anyone could pick up seven. Which one do you think the monitor gets?

A one-slot Goose queue
struct Preview { frame: i32 }fn main() {    qlimit<Preview>(1);    let first = qput(Preview { 7 });    let second = qput(Preview { 8 });    print(first, " ", second, " ", qget<Preview>().frame);}
  1. 1The limit applies to messages of type Preview.
  2. 2Eight arrives while seven still occupies the slot.
The native executable printed “true false 7” using Goose runtime 4d3da949e563.

Seven wins. A full queue refuses the incoming value and the producer can keep going. Ignore that boolean and you’ve built a monitor that quietly drops its freshest picture. The type matters too. Two cameras using the same message type feed the same queue. Putting a camera ID in the message identifies the sender once you’ve received it. It doesn’t route it to a particular screen. Goose’s queue rules.

Let the screen ask for a picture#

I’d turn the conversation around. Let capture keep a single pending preview, which it can replace whenever a newer frame arrives. The preview worker asks for one when it’s ready. Now only the owner changes the pending picture. Nobody has to reach into another thread’s queue and yank out a frame it might have started reading.

  1. Camera

    Stores frame 5, then replaces it with 6.

  2. Worker

    Finishes its previous render and asks for another.

  3. Camera

    Replies with 6 and clears the pending slot.

One possible exchange when the worker becomes free at 50 ms. Each request admits one preview.

If the request arrives early, capture remembers it and answers on the next exposure. On shutdown it owes that waiting worker an end message. Meanwhile the recorder gets every original on its own path. A disk stall can still exhaust the capture pool. Eight empty slots at one exposure every 10 ms buy about 80 ms to recover. After that we have to slow capture, find more storage, or tell the photographer that recording has a gap.

That’s the test I’d run at rehearsal. Stall the disk, turn the coat, and check the originals by exposure number. Then slow just the monitor and look at the silk again. I want to be able to drop three previews on purpose and still hand the photographer the one frame everybody came for.