Radical polymorphism for reactivity

This post collects together notes from a Claude session last month where I speculated that the performance and memory footprint of reactive systems could be radically improved whilst at the same time extending their reach into cyclic and bidirectional regimes that are already handled by fluid.cell, as well as notes left in my review for Tom Larkworthy’s “Dataflow Soundness Problems with the Observable Runtime” (in press) presented at the December 2026 Winter Substrates workshop.

The Reactive Graph Need Not Be Treated as Homogenous

Just because there is the potential for incoherent updates in some parts of the graph, doesn’t mean we need to give up the guarantees and efficiency we can expect in the parts of the graph which are “statically” analysable to be “good”. The seed of this is in my notion of a “good function" which implies that certain kinds of expression could expect to be statically “blessed” by inspecting their contents and finding that they are free of certain kinds of constructs — for example those which might consume unbounded computation, or issue side effects. This may be similar to the idea you are on to with your “linter on steroids”. I elaborated this a bit further in this blog posting of last year, “Hierarchy of good functions” the further up one is on this hierarchy, the more sound are the reactive guarantees which can be exported to your neighbourhood in the graph, and one’s position on this hierarchy is very cheap to assess statically.

Hierarchy of good functions

  • The identity – which in imperative memory ontologies appears as “aliasing”. “The same content knowably in more than one place”, which could be honoured by genuine aliasing in the underlying memory model, but at the very least should be trivially write-through, that is, “The same content knowably writeable at more than one address”.
  • Linear functions – genuine linear functions such as C = 5 * (F - 32) / 9, boolean NOT, etc. which can be “invertible on sight” when seen by the parser without the user needing to do anything about it.
  • Manually inverted functions – the user manually supplies an inverse and is assumed to know what they are doing.
  • Good functions proper – A closed algebra of blessed functions not doing excessive computation and likely not invertible at all
  • Anything else

This idea of inhomogeneity / “lumpiness” in the graph is one I’ve been talking more about with Orion Reed this year. It was a big lightbulb moment when I realised that one needn’t have one single monolithic reactive library managing everything with a central fascistic “Node” type describing everything that a node could do or should contain. I was nudged into this after implementing bidirectionality in fluid.cell and realising that 99% of cells simply didn’t need it - but just a few really do. I then thought - if we implemented cells that were polymorphic with respect to this, and merely conformed to a more abstract protocol of how they were meant to behave, couldn’t we loosen the contract still further and not bother to reify large parts of the graph as separated objects in memory at all? This led to this crucial exchange with Claude last month - https://claude.ai/share/ffd5f2b3-5a67-4e76-b485-cfedafaa4d19 the important bit is following my response “In using fluid.cell to implement the substrate” about halfway down.

In that and the exchange following, Claude sketches out what looks like a believable plan for doing without a conventional reactive representation for large parts of the graph entirely. I think this is going to be essential at some point given the huge inefficiency of my static publishing pipeline (it’s currently running at approx 6-8x slower than Hugo - which isn’t much of a realistic penalty since people aren’t going to run it locally in practice, but it would be nice to do better).

Claude’s plan for radical polymorphism

Q: On observing in reactivity for malleability that bidirectionality in user-land was desirable, and that cyclic relationships seemed inevitable in supporting the substrate, I considered that these should be treated by a common mechanism in the reactive implementation. However, the result of this has been hugely wasteful - I now have thousands of reactive nodes with an “inEdges” array with one entry, and I think maybe not even a single one that validly has more. But all the same the original requirement remains, and on the other hand it seems that we largely want to support the substrate’s lack of DAG-ness by other means. This suggests the need for a kind of “radical polymorphism” where we intend to morally treat a variety of structures as if they were valid reactive nodes - to start with, traditional node-edges with a single updater, and the rare examples of genuinely bidirectional nodes to support those occasional cases of user-configured cyclicity. And so on the other hand - FluidIL.js filled with examples of what I called “cod reactivity” - that is, effects and computed which manually bashed on “set” to update some other piece of state because I started from preact-signals which didn’t support other graph topologies in the first place. But now having implemented fluid.cell supporting free topologies it seems that I don’t really want to use it - for the kinds of reasons sketched above, as we see for example in cases like “scope ticks” that there are always going to be kinds of graph structures beyond its effective reach. What FDS seems to promise is that we can start to comprise cod reactivity as a more officially blessed kind of reactivity, in line with your remark above that what is shared amongst the varieties of reactivity is the scheduler and update/staleness idiom rather than actual reactive node representation per se. There are many kinds of reactive relationships that one is going to want to honour by means of independent record-keeping - e.g. the fact that update of a layer is going to hit all components which are derived from that layer, rather than being forced to push this record-keeping into the structures of the reactive algorithm. And also it seems to be emerging that there are many kinds of reactive nodes whose identity is completely settled simply by their “address”, to the extent that one might not even need to allocate them as objects at all in the first place if they are unreferenced - seeming to emerge from the many kinds of “reactive caches” that the substrate is accumulating that are keyed by some kind of local site path. The risk of “cod reactivity” was “broken graphs” - that is, graph topology that couldn’t be overseen by the reactive engine and so was at risk of glitching. But FDS and a priority-based scheduling system seems to promises us resistance to the harmful consequences of this glitching, and even a somewhat principled route to late-scheduling glitches themselves. Is there anything supporting this that we can learn from Solid or any other art that is out there, and what other observations/risks are on the horizon?

A: I think your conclusion is sound, and there is good prior art for each part of it. The most useful lesson is from Solid 2.0. It has also concluded that writes made from inside computations, your “cod reactivity”, need to be allowed. But it allows them only through sanctioned channels whose rules the scheduler understands. That is the shape I’d aim for: a blessed form of cod reactivity, not unlimited cod reactivity.

What Solid 2.0 does about cod reactivity

From the RC source:

  • The default is a diagnostic error. setSignal in core/core.ts reports REACTIVE_WRITE_IN_OWNED_SCOPE when a write happens inside a computation. The message tells you to move the write outside, or to set ownedWrite if it is intentional. So a write from a computation needs an explicit declaration on the target.
  • Projections are a firewall that makes such writes safe. The header of store/projection.ts explains that the firewall exists so that writes from inside a computation are safe, because the derive owns its leaves. The cost is an ordering obligation: before any value is served through the projection, the derive is brought up to date without the reader subscribing to it. The writes are staged in a draft and adopted when the flush commits.
  • A latch for missed wakes. REACTIVE_MISSED_WAKE (#3037) records the case where a pass writes to a link that the same pass had already validated, so the node is rerun at the end instead of the wake being silently lost. That is the classic failure of cod reactivity, recognised and handled by the scheduler.

The principle behind all three is ownership: a computation may write only to state it owns, or to state that has declared it accepts such writes. That limits where cycles can arise, and it gives the scheduler a place to stage the writes. Your substrate already has a natural owner for everything, the component shadow at a site. A rule like “a cod write may target only state owned by the writer’s site, or a declared channel” would bring most of FluidIL.js into scope. Writes like dynamicLayerNames.set inside flatMergedComputer, or ownScopeTick.set inside scopeEffect, would become declared, staged writes, rather than pokes into some other part of the graph.

Other art that matches the pieces of your plan

Nodes whose identity is settled by their address: Nominal Adapton. Hammer and colleagues (2015) gave memoised nodes first-class names, so that a node in one run is matched to the same node in the next run by its name, not by when it happened to be allocated. Salsa’s interned and tracked structs do the same: an entity created inside a query is identified by its creating query plus its own key, and it is recreated with the same identity on the next run. Both are your observation that a site-keyed reactive cache doesn’t need an object until something refers to it. The address is the node; an object is just a cache of it.

Running down a linear list with reordering: Excel’s calculation chain. Excel recalculates by walking an ordered list of cells. When a formula reaches a cell that hasn’t been calculated yet, it moves the dependent cell later in the chain and continues. The order is learned and saved for the next run. That is “crank the handle on a list, with reordered priorities”, and it has been in production for decades. Build Systems à la Carte calls this a restarting scheduler. Its counterpart is a suspending scheduler, which is what pulling recursively gives you. The restarting kind is the one suited to dependencies that aren’t known in advance, which is the substrate’s normal case.

Bookkeeping kept outside the graph. Your example of “updating a layer affects every component that uses it” is an index in Datalog’s sense: a relation uses(component, layer) that you maintain yourself and query on change, rather than an edge per pair. Semi-naive evaluation is the method for recomputing only what a change touches: each round processes only the facts that were new in the previous round. That is the formal version of a scope tick, or a layer revision, per region.

Glitches pushed to the end, not banned. I covered CALM and stratification earlier. The specific point here is that a glitch in a monotone stratum is harmless if nothing in a later stratum has consumed it yet. Fully deferred stabilization with stratified priority provides exactly that guarantee. So the scheduler doesn’t eliminate glitches; it makes sure they are never observed across a stratum boundary.

A minimal contract for “radical polymorphism”

If many structures are to count morally as reactive nodes, each needs to answer only a few questions. I’d frame this as a protocol, not a shared class:

Question Classic cell Bidirectional cell Address-keyed cache (scope, layer, query)
What is your key? Object identity Object identity Site or name string
Are you current as of revision r? _state _state plus fit Compare recorded revisions
Recompute or validate Single updater Choose an edge Cache function
Who must be woken when you change? Observer list Observer list Readers of the address (log or revalidation)
What did you read? (provenance) Sources Sources Recorded keys

Two observations follow from the table:

  1. The bidirectional cell becomes its own rare node kind. _inEdges arrays, edge choice, fits and _consumedSources move onto that kind only. Ordinary cells go back to a single updater, which addresses the waste you described: thousands of one-element _inEdges arrays.
  2. The bottom two rows are not optional for moral nodes. This is the main risk below.

Risks to plan for

1. Missed wakes are still the core hazard. Fully deferred stabilization protects effects from glitches, but it doesn’t make a stale read safe. Suppose a cod write lands on an address that a computation in the same pass has already read. That computation’s result is now wrong, and nothing will rerun it unless the scheduler knows who read that address. Solid needed REACTIVE_MISSED_WAKE for this even with a full graph. For moral nodes, the minimum requirement is that reads of an address be recorded at least coarsely, as a revision per region, so that writes during a pass can be checked against them. “As if” reactivity that doesn’t record reads gets you back to broken graphs.

2. Contextually informed analysis needs provenance, so moral nodes must record what they read. The analysis your article proposes, explaining every pending effect by its chain back to source data, works only if moral nodes keep provenance as well. allocateEffectScheduler currently runs scheduleEffects inside untracked, and that is exactly where the chain would break: the pause point would exist, but it couldn’t explain why an effect is pending. Recording keys in the side table, even without subscribing, keeps the explanation intact at very low cost.

3. Termination needs a stated guarantee. Cycles made by cod writes are invisible to a graph engine, but a queue can still notice them. Give each iteration coordinate a budget and treat exceeding it as an error. Report the non-converging keys together with their provenance, much as Excel reports a circular reference. Cycles that are monotone, such as layer accumulation, converge by construction. The ones to watch are writes that can retract what was written before: an empty potentia, clearScope, goneShadows.

4. Priority inversion and starvation. Once policy priorities are allowed, a low-stratum task that keeps re-enqueueing, such as a self-accumulating layer that never settles, can starve everything above it. Bound the work per stratum per stabilization, and make “yield to the next stratum” an explicit decision the scheduler records, so it can be seen in analysis.

5. Garbage collection of address-keyed caches. Address-keyed nodes that are never allocated still leave entries behind: memos and recorded dependencies in sitedRefMap, queryILMap and the shadowMap. Salsa needed revision-based eviction for this. Your disposeLayerEffects diffing old and new shadow maps is the natural place to sweep stale entries, since a site that disappears from the new map has been dropped by definition.

6. Interaction with pending values. "pending" and staleValue cross fit boundaries today. Once iteration coordinates exist, a pending value should be stamped with the coordinate it was produced at. Otherwise a value that resolves asynchronously can land in a later iteration and look like a fresh change rather than the completion of an old one. Solid’s lane and transaction machinery, with held stagings and promoted writes, is largely about this problem. It suggests the problem will take real design effort.

A suggested order of work

  1. Write down the protocol (the table above) and make the existing cell one implementation of it. Move multi-edge support into a separate node kind.
  2. Add a declared channel for cod writes. It stages writes for the next iteration coordinate, and in development builds it diagnoses undeclared writes made inside a computation, as Solid does.
  3. Convert scope resolution to address-keyed memos that record what they read, as a test of the protocol’s bottom two rows.
  4. Then move to the queue-based stabilizer. By this point every participant can answer “who read me?” and “what did I read?”, which is all the queue needs.

This order leaves the user-facing dataflow on ordinary cells throughout. The substrate moves over one subsystem at a time, and at each step you can measure whether the bookkeeping has disappeared or just moved somewhere else.