Skip to content

Ariadne: the read lane keeps its results until what they read is written - #1084

Merged
transfix merged 3 commits into
masterfrom
feat/ariadne-reactive-cache
Nov 9, 2026
Merged

transfix merged 3 commits into
masterfrom
feat/ariadne-reactive-cache

Conversation

@transfix

@transfix transfix commented Nov 9, 2026

Copy link
Copy Markdown
Owner

The read lane now keeps its results: a frame re-runs only the expressions whose inputs changed. Stacked on #1082 (the same eval paths, and the counter beside reactive_skip_count); review the last commit.

The problem. Until now every visible_when, enabled_when / disabled_when, computed bind: / text, tooltip, options and repeat: count ran again every frame; only the parse was cached. A nicotina card has about 21 of them. That makes a ten-card feed about 210 runs a frame (around 12,600 a second at 60 fps), nearly all giving last frame's answer. On single-threaded arigl-web, which shares the thread with picture and video decode, they spent the 30 ms budget.

What is kept. ReactiveEngine keeps each result per scope and per expression text (so each {i} row is its own), along with what the run read:

  • the state paths its readers named. state-get, state-exists, state-children, state-data-get and state-json are wrapped to note them, as absolute normalized paths; no path means the whole scope;
  • the (has? …) answers it got. has? is answered once a frame per name and noted.

When a kept result is used. A result is reused, not run, until one of these happens:

  • something is written to a path it read, or to an ancestor or a descendant of one;
  • a name it asked about answers otherwise.

Writes are seen through the state tree root's childChanged, which value, data, touch, link changes, removeChild and the expiry sweep all fire, from any thread. Its slot only appends the path to a mutex-held log, capped at 4096 a frame (past that, everything is stale). The frame thread folds the log into per-path generations before each lookup: a written node's own, and the newest write at or under each path. A frame with no writes costs one atomic load per lookup.

What is never kept:

  • a result that read (time-now) or an expiry (state-is-expired, state-has-expiry);
  • a result that read a node through a link, whose target's writes are signalled under the target's path;
  • an expression naming a reader that is bound but couldn't be wrapped;
  • errors, timeouts and skips.

The budget (L24). A kept result isn't run, so it never counts against the 30 ms and is never skipped.

Housekeeping:

  • a result no frame used for 300 frames is dropped (a repeat's rows scrolled away);
  • the generation maps start over past 65,536 written paths.

API: Runtime::reactive_eval_count(), the expressions that ran.

Cost: while a Runtime has a read lane, every state write in the app builds its path once for the root's slot. Without a slot it builds none.

Not done (the optional step in the request): re-running stale entries on the app scheduler while the frame draws the old value. With nicotina's controller precomputing card decisions, an idle feed now runs nothing, and a changed post runs only its own card's expressions.

Docs: ARIADNE.md §2.1.

Tests (ariadne_media_test, AriadneReactiveCache):

  • AFrameThatWroteNothingRunsNothing
  • AWriteRerunsWhatReadItAndNothingElse: the path, a descendant, an ancestor, an unrelated path, a same-value write, another thread's write.
  • TheClockAndALinkStayLive
  • ARepeatsRowsAreKeptApart
  • AKeptResultIsNeverSkipped
  • AChangedHasAnswerRerunsIt

Locally on Windows (FTXUI on), every Ariadne suite and the cvcgl_imgui_* / cvcgl_ari* tests pass.

…arning

On the live nicotina page (arigl-web, real tx.wtf) a 10-post feed decoding pictures in wasm spends
the 30 ms read-lane budget on its first frames, and each expression it skipped became
"ari: reactive expr ... skipped - per-frame budget exhausted" through warn_once, which the page's
ariadneWarning shows the user. A skip is not the document's fault.
- Every read-lane path takes a skip the same way: last frame's value, else the fail-safe one, and
  no warning. predicate (visible_when / enabled_when / disabled_when): last answer, else hidden /
  disabled (one skipped before it ever ran warned). eval_text (computed binds, src): last text,
  else empty. eval_text_or_literal (tooltip): last text, else empty, not the expression's own
  source. eval_options: last list, else empty. eval_count (repeat:): last count, else 0.
- Real errors (parse, runtime, unbound, step / time cap) still warn once.
- Runtime::reactive_skip_count() counts the skips, for a host that logs them.
- The engine's String/StringList/Int outcomes say skipped, as Outcome did.

Docs: ARIADNE.md section 2.1; the set_reactive_frame_budget / take_reactive_warnings comments.
Test: ariadne_media_test's AriadneReactiveBudget.ASkipIsNeverAWarning.
Every visible_when, enabled_when / disabled_when, computed bind / text, tooltip, options and
repeat count ran again each frame (only the parse was cached). A nicotina card has about 21, so a
ten-card feed ran ~210 a frame, nearly all giving last frame's answer, and on single-threaded
arigl-web, sharing the thread with picture and video decode, they spent the 30 ms budget.
- ReactiveEngine keeps each result per scope and expression text ({i} rows apart), with the state
  paths its readers named (state-get, state-exists, state-children, state-data-get, state-json,
  wrapped to note them) and the (has? ...) answers it got (each name asked once a frame).
- It is reused, not run, until a write lands on a path it read, an ancestor or a descendant of
  one, or an asked name answers otherwise. Writes come from the tree root's childChanged (value,
  data, touch, links, removeChild, the expiry sweep), on any thread: the slot appends the path to
  a mutex-held log, folded into per-path generations by the frame thread before each lookup.
- Never kept: a result that read (time-now), an expiry, or a node through a link; an expression
  naming a reader that could not be wrapped; errors, timeouts, skips.
- A kept result is not run, so the frame budget never skips it.
- Unused for 300 frames: dropped. Runtime::reactive_eval_count() counts what ran.

Docs: ARIADNE.md section 2.1.
Tests: ariadne_media_test's AriadneReactiveCache (an idle frame runs nothing; a write reruns what
read it; the clock and a link stay live; a repeat's rows are kept apart; a kept result is never
skipped; a changed has? answer reruns it).
# Conflicts:
#	docs/ARIADNE.md
#	inc/cvc/ariadne/ariadne.h
#	src/cvc/ariadne/ariadne.cpp
#	src/cvc/tests/ariadne_media_test.cpp
@transfix
transfix enabled auto-merge (squash) November 9, 2026 20:01
@transfix
transfix merged commit 0abe894 into master Nov 9, 2026
20 of 30 checks passed
@transfix
transfix deleted the feat/ariadne-reactive-cache branch November 9, 2026 21:24
transfix added a commit that referenced this pull request Nov 9, 2026
…andles (#1099)

One conflict, in ariadne.cpp's includes: both sides kept. Master's cache notes
state writes under a lock on the writer's thread, so writes from an isolated
document's group on a pool thread invalidate a kept result like any other.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant