Skip to content

Ariadne: the runtime's frame holds its lookups and writes its telemetry at a rate - #1478

Closed
transfix wants to merge 1 commit into
masterfrom
perf/ariadne-runtime-frame
Closed

transfix wants to merge 1 commit into
masterfrom
perf/ariadne-runtime-frame

Conversation

@transfix

@transfix transfix commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

The Ariadne runtime's frame (AriRuntime::frame) cost more in a browser than drawing the scene did: with about 24 posed vehicles on a city, it walked state paths and formatted every entity's and the physics world's telemetry as text, every frame, and the camera's clipping-range fit ran a VTK pipeline update for every actor each frame anything moved. This makes the frame hold its lookups, write what changed, and write the telemetry at a rate.

What changed

cvc::state: change counts, and a held lookup

  • state::revision(): a count that moves with each change of a node's value or data, as valueChanged/dataChanged fire. A reader can tell the node was not written since it last looked, without copying the value or connecting a slot.
  • state::shapeRevision(): one count per tree that moves when a node is added or removed, or a link is made, moved, cleared or has its mode or writability changed.
  • cvc::state_key (inc/cvc/state/state_key.h): a path looked up once and held, walked again only after the tree changed shape. Its read/write/find/get are findThroughLinks/childThroughLinks/findDescendant/operator(), with their semantics. It pins the node and the way to it.
  • state::value(string) takes the node's lock once instead of four times. The link check, the read-only check, the compare and the store are now one hold; the behaviour is the same.

The world's telemetry at a rate (physics.telemetry_hz, seeded 10)

  • Each frame that steps still writes physics.stats.{tick, time, step_ms, bodies, active_bodies, contact_events, saturated}, and hash when asked.
  • The lines (step_ms_history, nodes, vehicles) and each entity's pose, speed, books and command are written on the frame whose steps cross into a new 1/rate of world time. A period is round(1 / (rate × fixed_dt)) steps counted from tick 0, so the ticks are the same at any frame rate, drawn or headless.
  • 0 writes them every frame that steps.
  • A world that stops (physics off, or the clock held) writes them once more, where it stopped.
  • An entity's keys are all written when it is listed, and again whenever the entities change (rev). Its identity, ids, count and rev are never late.
  • Only values that changed are written. The text formats are unchanged (%.6g; the stats' %.17g, formerly an ostringstream). Something else writing one of these keys is seen through the node's revision, and the next write puts the value back.
  • WorldVehicles::publish() and SceneWorld::publish_stats() still write everything; WorldVehicles::publish(bool telemetry) is the rate's form.

Held lookups in the frame

  • Scene visible: bindings (sync_scene_visibility): skip a frame in which neither key was written.
  • Clip offsets, bound opacity (applied again only when it changes or the node is drawn again), repeat: counts and data nodes' status.
  • A ribbon's source (now on the node's revision instead of signal slots) and its window bounds.
  • Pose entities' pose keys and packed poses, read on each step: the packed value is no longer copied each step.
  • The poses table's scan, skipped while no entry was written, added or removed.
  • WorldVehicles::poll()'s keys, adaptive quality's two keys, and the key-capture key.

cvcGL

  • GraphicsNode::updateTransform no longer sets a vtkTransform that nothing read. Every pose rebuilt its concatenation, allocating and freeing VTK objects.
  • A GeometryNode's mapper is Static: its input is the node's own polydata, changed in place, with no pipeline above it. The camera's clipping-range fit asks every actor for its bounds each frame anything moved, and the pipeline updates were most of what that cost.

Docs: docs/ARIADNE.md (the telemetry rate, the entities' keys), scene_world.h, world_vehicles.h.

Measured

On a bench document: 24 pose entities driven by timed poses on the small Austin data city (scene-austin-south-small), each with an entity label, two windowed ribbons, a draped link and a marker (repeat:, each with a bound visible:), and the physics panel. rt.frame() was timed with a scratch timer in arigl that is not part of this PR.

before (master) after
Native rt.frame, wall time (1/60 s frames, 1280x720) 8.1–9.0 ms 2.8–2.9 ms
Native rt.frame, instructions (callgrind, steady frames) 15.9 M 2.98 M
of which AppRuntime::drain 10.4 M 2.29 M

| of which the camera's clipping-range fit | 5.4 M | 0.69 M |

Browser numbers (wasm-mt, JSPI and wasm exceptions, headless Firefox 158 and Chromium 145) are not clean yet: this machine's GPU and CPU were shared with stray browser runs. Medians pointed the same way (Firefox p50 about 12 → 8 ms, Chromium 9.4 → 5 ms, at 10–15 fps).

Tests

  • New: state_key_test (the counts, the held lookup through links, removal and re-creation, a write through a held node).
  • New: AriadneWorldVehicles.TheTelemetryIsWrittenAtItsRate (the per-frame stats every frame; the lines and an entity's keys once per period; 0 is every frame; a stopped world writes once more; a foreign write is put back).
  • New: AriadneBind.SyncFollowsEveryChangeWhileItSkipsTheFramesWithout.
  • The existing ones pass unchanged: ariadne_scene_world_test (including the pinned pose-document hash), ariadne_runtime_test, ariadne_bind_test, state_test, state_link_test, the cvcGL ariadne suites and the rest of ctest. Locally 8398 of 8401 ctest pass. The three that fail are this machine's build: it has no cvc::planar (cvcgl_contour_lab, cvcgl_volume_grid_contours, and cvcgl_ari_golden's tiler and skeleton pages), and its GPU's pixels differ from cvcgl_ari_golden's goldens by the same counts with and without the mapper change. CI is the check for those.

…ry at a rate

The Ariadne runtime's frame (AriRuntime::frame) cost more in a browser than drawing the scene: with
two dozen posed vehicles it walked state paths and formatted every entity's and the physics world's
telemetry as text every frame, and the camera's clipping-range fit ran a VTK pipeline update for
every actor each frame anything moved.

- cvc::state: revision() (a node's value and data changes) and shapeRevision() (its tree's nodes
  and links), and cvc::state_key, a lookup held until the tree changes shape. value(string) takes
  the node's lock once.
- The world's telemetry: the per-frame stats as before; the stats' lines and each entity's pose,
  speed, books and command at physics.telemetry_hz (seeded 10, in world time; 0 = every frame), and
  once more where a world stops; a new entity's keys, and all of them after a change of the
  entities, at once. Only what changed is written.
- Held lookups for visible: bindings, clip offsets, bound opacity, repeat counts, data nodes,
  ribbons, pose keys and packed poses, the poses table, WorldVehicles::poll, adaptive quality and
  the key capture.
- cvcGL: GraphicsNode no longer rebuilds an unused vtkTransform on each pose, and a GeometryNode's
  mapper is Static (its input is the node's own polydata, with no pipeline above it).
@transfix
transfix marked this pull request as draft November 23, 2026 03:29
@transfix

Copy link
Copy Markdown
Owner Author

Draft: this overlaps #1477 (the same runtime-frame fix from another session, opened first, its own cvc::state_key and structure epoch), so both can't land. Unless the sessions decide otherwise, #1477 lands and this becomes a follow-up rebased on it, carrying only what #1477 doesn't have: the camera's clipping-range fit (GeometryNode's mapper Static; it was 70% of AriRuntime::frame on the bench once the drain was cheap), GraphicsNode's unused vtkTransform rebuilt on every pose, the telemetry rate (physics.telemetry_hz), and the per-node revision that lets bindings skip unwritten keys. The head as opened is 25a749b.

@transfix

Copy link
Copy Markdown
Owner Author

Closed as a duplicate: the runtime-frame task belongs to another session (its #1477). The branch perf/ariadne-runtime-frame (25a749b) stays for reference: it has the telemetry rate (physics.telemetry_hz) and the per-node revision skips #1477 doesn't, if that session wants them.

@transfix transfix closed this Nov 23, 2026
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