11
Progress and estimated time to completion
The essay's case study ties the primitives together. A stream is copied into an array. Each arrival pushes discrete signals: progress and throughput. From those we derive an estimated stop time, and from that a continuous behavior that a progress bar polls on every animation frame.
We could update a progress bar whenever we receive a new value, but frequently we would want to display a smooth animation continuously changing. … Values that lack an inherent resolution are continuous. It becomes the responsibility of the consumer to determine when to sample, pull or poll the value.
Two progress bars, one stream
discrete · pushed by a signal on each value—
continuous · behavior polled every frame0.0%
index / length(now − start) / (estimate − start)latest estimated stop
received
—
throughput
—
elapsed
—
eta
—
The arithmetic, live
progress = index / length
→ run to see values
throughput = index / elapsed
→ run to see values
stop = start + elapsed * length / index
→ run to see values
progress(now) = (now - start) / (stop - start)
→ run to see values
Turn up the unevenness and watch the slow patch in the middle: the steps stall, the estimate line jumps right, and the smooth bar slows down to meet it. That is the behavior re-deriving itself from each new discrete estimate.
Discrete time series · push
// Discrete: pushed each time another value arrives.
var progress = index / length;
var elapsed = now - start;
var throughput = index / elapsed;
// Estimated time of completion.
var stop = start + elapsed / progress;
var stop = start + elapsed / (index / length);
var stop = start + elapsed * length / index;Continuous time series · poll
// Continuous: derived from the last known estimate,
// sampled whenever the consumer wants — here, every frame.
var progress = (now - start) / (estimate - start);For a smooth animation of a continuous behavior, the frame rate is a sensible polling frequency. Ideally progress proceeds linearly from 0 at the start time to 1 at the stop time.
- why it mattersProgress measured on arrival is discrete: it does not change between events, so it is pushed. The stepped bar is honest but jerky, and it freezes whenever the stream stalls.
- why it mattersThe estimate turns those discrete measurements into a continuous function of time. The display picks its own sampling rate; the stream never needs to know there is an animation.
- why it mattersOne task, three primitives: a stream with back pressure moves the data, signals report on it, a behavior is sampled for display. Choosing the right one for each role is the point of the theory.