observablehq / runtime

The reactive dataflow runtime that powers Observable Framework and Observable notebooks
https://observablehq.com/@observablehq/how-observable-runs
ISC License
1.01k stars 71 forks source link

Defer recompute until all variables are computing. #220

Closed mbostock closed 3 years ago

mbostock commented 4 years ago

Revisiting #108.

Ref. https://talk.observablehq.com/t/error-importing-d3-radial-tidy-tree/2626

mbostock commented 4 years ago

Would love some help testing this.

mbostock commented 4 years ago

Add’l ref. a601aba88046a626@227...6c9da6fb50c966f0@349

mbostock commented 4 years ago

I think we should try deploying this tomorrow.

jashkenas commented 4 years ago

Putting in a couple of notes on this, for future us:

The fundamental problem we’re trying to solve with this branch is an under-specified total ordering of our runtime computation graph, specifically with the interaction between the evaluation order of generators that are yielding new values continuously, and downstream cells that depend on their values.

The downstream cell may compute "synchronously" (albeit, through a promise), or asynchronously, and when it computes synchronously, we want the evaluation order to be coordinated with the yielding of its input generator, so, given:

a = {
  let i = 0;
  while (true) yield ++i;
}
b = a

We want our notebook to be able to observe this ordering:

mbostock commented 4 years ago

Sadly, after further testing this does not appear to be doing what we want: the postcompute promise is still resolving too soon, before the transitive subtree of the generator’s outputs.

Also, our effort focused on deferring the first recompute the generator, but I suspect there’s a similar issue with subsequent recomputes.

And I’m also not entirely certain that it’s appropriate a generator to resume immediately, or if the generator should wait until the next animation frame before resuming. But changing that behavior would introduce some flickering for notebooks that currently assume yield will resume immediately (for the first yield).