Skip to content

Fleets: kept fleet lookups, D3 as OW7's first part, and FL2's first part (a world's vehicles drawn at scale) - #1475

Merged
transfix merged 9 commits into
masterfrom
feat/d3-world-worker
Nov 24, 2026
Merged

transfix merged 9 commits into
masterfrom
feat/d3-world-worker

Conversation

@transfix

@transfix transfix commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Three commits: the fleet lookup cost #1449 left, the fleets roadmap's D3 built as OW7's first part, and the D3 world's allowed lag as a setting.

1. A placed vehicle keeps its fleet and its index in that fleet's navigator

At 2000 kinematic vehicles with summary keys, a tick looked a vehicle's fleet up 28,000 times (14 per vehicle). Each lookup searched the fleets by the key's parts, at about twice the cost of FL1a's plain find. A tick also searched the navigator's ids for an index about as often.

  • fleet_of(): a placed entity's fleet is set and cleared together with its navigator id. An entity that isn't placed is searched for as before.

  • index(): kept on the entity until an agent comes or goes in that fleet (agents_rev).

  • Debug builds assert both against the search. The scene world, holon, holon sync and server document suites pass with the asserts on.

  • Timed in one process on a busy machine, where a whole-tick A/B was lost in the noise:

    Lookup Searched Kept
    Fleet 124 to 141 ns 3 to 6 ns
    Index 102 to 122 ns 5 to 8 ns

2. D3 as OW7's first part: a drawn host's world steps on a worker, in a local holon

A holon has no thread of its own, so the worker is new. No holon.h change; this was coordinated with the One World session (#1444) on dev.tx.wtf.

  • cvc::ariadne::world_worker attaches a SceneWorld to a server-role holon of its own (physics on, at the world's rate).
    • Its thread keeps the holon's lockstep clock tick for tick behind the host's clock, one quantum at a time, so the world takes the same steps the host's own follow() would.
    • The host holds lock() for its frame. The worker takes the lock for each step and lets a waiting host go first.
  • SceneWorld::set_deferred: follow() only steps and writes no key, because a state subscriber runs on the thread that writes. The host calls publish_due() under the lock.
    • A restart anchors the world on the holon's clock again at once.
  • SceneClockDriver::hold(): a world further behind its clock than the scene's max_lag (section 3) holds the clock. It then runs slower than its speed, as it would on the frame's thread, instead of falling further behind.
  • cvcGL: AriRuntime::set_world_thread starts a worker for the main scene's world and holds its lock through frame().
    • tick_scene publishes what the worker ran and draws from the poses it captured.
    • The adapter stops the worker before a reload or clear replaces the world.
  • arigl run --world-thread turns it on. Snapshots, --terminal, wasm, the headless hosts, the gym and arisrv are unchanged.

3. How far a world may lag its clock is a setting, the same on every host

scene: clock: { max_lag: <s> } takes seconds of world time at 1x. It grows with the speed, by ceil(speed) past 1x, the way the clock's catch-up does. It must be more than 0 and at most 10 s. Before, the worker allowed a fixed 30 quanta, which is 0.25 s only at 120 Hz.

  • On a worker (--world-thread), it is how far the world may trail its clock before the host holds the clock. world_worker::options::max_lag is now in seconds, with kSimCatchup (0.25 s) as the default. A value outside the range is refused, and the world stays on the frame's thread.
  • On the frame's thread, it is the most catch-up one frame may run. That covers every single-threaded host, native or browser: arigl without the flag, the browser, snapshots and the headless AppRuntime. SceneClockDriver sets the clock's stall guard from it when it binds, through the new world_clock::set_max_steps_per_advance, which keeps the tick. Unset, the clock keeps the guard its host gave it, so no existing document changes.
  • Single-thread wasm: world_worker::available() is false. The worker tests skip there, and the browser's arigl prints once that it steps the world on the frame's thread when given --world-thread.

Not yet (ARIADNE_WORLDS §18.2):

  • avatars and participants in the local holon;
  • the worlds of scenes: entries;
  • the gym and the GRL-SNAM hosts on it;
  • the drawn host as the holon's client.

Tests and numbers

  • AriadneWorldWorker.StepsTheWorldAsTheHostsFollowWould: 24 kinematic and 4 Jolt vehicles, through a restart. Poses match the host's own follow() bit for bit, and the keys are written on the host's thread. Passed 30 repeats.

  • cvcGL test_world_worker_drawn: bodies and their drawn pose end where the frame's own follow leaves them. Passed 5 repeats.

  • Section 3: WorldClockTest.TheStallGuardChangesInPlace, SimTickTest.ACatchUpIsWholeQuantaAndGrowsWithTheSpeed, AriadneScene.ClockBlockTakesAMaxLag, AriadneSceneWorld.TheScenesMaxLagIsTheCatchUpAFrameMayRun, AriadneWorldWorker.TheWorldMayTrailItsClockByMaxLag.

  • Suites passing locally (Windows, Release): ariadne_scene_world_test (114), holon_test, holon_sync_test, ariadne_server_document_test, and cvcgl_ariadne_physics, cvcgl_ariadne_scenes, cvcgl_ariadne_realize.

  • arigl, 200 kinematic vehicles at 3.6x, alternating runs (median frame):

    Stepping on Frame fps World speed
    The frame's thread 66.4 ms 15.0 3.6x
    --world-thread 58.3 ms 17.1 3.6x

    The rest of each frame is drawing 200 vehicles, which is FL2's job. At 800 vehicles the drawing alone takes seconds a frame.

FL2, first part (#1489, merged into this branch)

#1489 was stacked on this branch and is squash-merged into it, so this PR lands D3 and FL2 together. Master is merged in again (6564bc1; #1471 replaced #1472's wheeled look with a parted look), and FL2 draws a parted look at scale.

Each world entity was a scene node of its own: a box look is six boxes and
a group, so 200 vehicles were 1400 actors. On arigl, 200 kinematic vehicles
at 3.6x took 61 ms a frame (19 of runtime, 42 to 46 of drawing), and 800
took seconds.

cvc::gl::ariadne::entity_view (entity_view.h) is the view of a set of
entities, whatever feeds it:

  • set_entities (who each is: archetype, fleet, team, colours, look, size);
  • promote, from the camera and the ids followed;
  • then pose and draw each frame.

Its bodies layer draws the entities it takes as one mesh per archetype and
LOD rung:

  • a fitted model gets four rungs (nav_city_swarm and nav_city_drive as Ariadne documents (nav_swarm, swarm_layer) #1358's swarm rungs; decimate_mesh moves
    to mesh_lod.h and the swarm uses it there), a box look one;
  • each copy is posed in 3-D, normals too, and culled on the frustum's
    sides. Near and far are left out: the renderer fits them to what it
    draws, and an unposed rung is a point, so a far plane fitted to it cut
    away the entities about to be drawn.

Promotion and layers:

  • promote (8) are drawn as their own nodes by vehicle_view: the followed
    (a camera's track.target, vehicles.watch, the vehicle a client drives),
    then the nearest. An incumbent keeps its node until another is a fifth
    nearer.
  • a layer of at most threshold (32) promotes them all, so small worlds
    look as before;
  • type: entity_layer (of: all | { fleet } | { archetype } | { team }, lod:,
    promote:, threshold:) declares a layer. With none, an implicit layer
    covers every entity.

Two feeds, the local and the server-side holon:

sync_vehicle_markers draws only the promoted, and adds or removes nodes as
promotion changes. A boat, a mesh file look without fit, or an entity no
layer takes keeps its own node.

Test cvcgl_ariadne_entities (37 checks, 5 repeats): the implicit layer,
follow, keep, the threshold, of:, the world on a worker, and the room.
Locally, cvcgl_ariadne_labels, _scenes, _realize, _swarm, _physics and
cvcgl_room_view also pass.

arigl, 200 kinematic at 3.6x with --world-thread, alternating runs:

  • 8 ms a frame (2.4 runtime, 5.4 to 6.6 drawing), against 61 with
    threshold: 100000 (each its own node);
  • 800 take 8 ms of drawing. Their world, at 16 to 18 ms a frame, is now the
    cost.

Not yet: the other layers (flags, goals, trails, path, belief, dots,
targets, follow, headlights), of: { fleet } on a client (the room's
identities carry no fleet), and swarm_layer moving here (FL3).

FL2: a parted look at scale, its wheels dark at every rung

#1471's parted look (look: { chassis:, wheel:, rig: }) is a fitted look whose
one-piece model is null, so the entity view drew every parted vehicle as a
node of its own.

  • vehicle_look_mesh_of: a parted look's mesh is its chassis and its wheels
    at rest, each point where attach_parted_model's nodes draw it (the chassis
    fitted per axis; each wheel at its fitted hub, a right one turned or
    reflected as its rig says), the wheels in a tyre's dark. One texture, the
    chassis's. add_part bakes a part by a 3x3 matrix, normals by its inverse
    transpose; the one-piece model goes through it too.
  • Role 3, the model's (white under its texture, else the entity's colour),
    so an untextured rung keeps role 2's dark.
  • make_rungs decimates each colour role on its own. A coarse rung kept no
    roles, so the wheels would have taken the body's colour.
  • sync_vehicle_markers keeps Ariadne: a parted vehicle look whose wheels roll and steer (replaces #1472) #1471's vehicle_wheels with the markers: a
    rebuild clears them, a demoted vehicle's go with its node.

Test cvcgl_ariadne_entities, parted: the mesh against attach_parted_model's
nodes (mirror turn and reflect, an axle offset); 40 at scale in the model's
four rungs, wheels dark at each rung drawn; one rung (lod: false), each
copy's chassis in its colour and its wheels dark.

…s navigator

A tick at 2000 kinematic vehicles with summary keys looked a vehicle's fleet up 28,000 times
(14 a vehicle), each a search of the fleets by the key's parts, about twice FL1a's plain find
(#1449 left it), and searched its navigator's ids for its index about as often.

- fleet_of(): a placed entity's fleet is set and cleared with its navigator id (place,
  remove_from_fleet, a failed placing, the world gone). A fleet outlives its vehicles in it, and
  an entity's key doesn't change while it is placed. An entity not placed is searched for as
  before.
- index(): kept on the entity until an agent comes or goes in that fleet (a fleet's agents_rev,
  bumped at each add_agent and remove_agent; an index past a removed one drops by one).
- Debug builds assert both against the search. The scene world, holon, holon sync and server
  document suites pass with the asserts on in a Release build.

Timed in one process on a busy machine (a whole tick's A/B was lost in its noise): a search took
124 to 141 ns and the kept fleet 3 to 6 ns; an index 102 to 122 ns and kept 5 to 8 ns. The
roadmap's 3.1 has it.
…r, in a local holon

A drawn host stepped its scene world (physics and the fleets' navigators) on the frame's
thread: at 3.6x 60 Jolt vehicles took two thirds of a core, 800 kinematic ones all of it. D3
(FLEETS_AND_NIGHT_ROADMAP.md) moves it off; Joe chose to build it as OW7's first part, the
world in a local server-role holon (ARIADNE_WORLDS.md 18.2). A holon has no thread of its own,
so the worker is new:

- cvc::ariadne::world_worker attaches a SceneWorld to a server-role holon of its own (physics
  on, holon_config_at the world's rate) and runs a thread that keeps the holon's lockstep clock
  tick for tick behind the host's, one quantum at a time, so the world takes the steps the
  host's own follow() would. The host holds lock() for its frame; the worker takes it per step
  and lets a waiting host go first. A step that throws stops it (error()); lag()/behind() say
  how far it is behind; wait_caught_up() is for tests and captures.
- SceneWorld::set_deferred: follow() then only steps. It runs no sync() and writes no key (a
  state subscriber runs on the thread that writes) and calls the worker's capture after each
  step; the host calls publish_due() (sync and the telemetry) under the lock. A restart anchors
  the world on the holon's clock again at once, since the host's clock may be back past where
  it was before the worker looks (the test caught that).
- SceneClockDriver::hold(): a world more than max_lag (0.25 s) behind holds the clock, so it
  runs slower than its speed, as on the frame's thread, rather than further behind.
- cvcGL: AriRuntime::set_world_thread starts a worker for the main scene's world at the next
  frame and holds its lock through frame() (input, pump, tick_scene); tick_scene publishes what
  the worker ran and draws from the poses it captured. The adapter owns the worker and stops it
  before a reload or clear replaces the world. arigl run --world-thread turns it on; snapshots,
  --terminal, wasm, the headless hosts, the gym and arisrv are unchanged.

No holon.h change (coordinated with the One World session, #1444, on dev.tx.wtf).

Tests: AriadneWorldWorker.StepsTheWorldAsTheHostsFollowWould (24 kinematic + 4 Jolt vehicles
through a restart: the same poses bit for bit as the host's follow, the keys written on the
host's thread; 30 repeats), cvcGL test_world_worker_drawn (bodies and their drawn pose as the
frame's own follow leaves them). The scene world (114), holon, holon sync, server document and
cvcGL physics suites pass. On arigl with 200 kinematic vehicles at 3.6x, alternating runs:
58.3 ms a frame against 66.4 on the frame's thread, the world at 3.6x both ways; the rest of
the frame is drawing 200 vehicles (FL2).
… host

A scene's clock: { max_lag: <s> } sets how far its world may fall behind its
clock: seconds of world time at 1x, growing with the speed as the clock's
catch-up does (by ceil(speed) past 1x), more than 0 and at most 10 s
(cvc::sim_catchup_valid). It was a fixed 30 quanta in world_worker, which is
0.25 s only at 120 Hz.

- On a worker (arigl --world-thread), it is how far the world may trail its
  clock before the host holds the clock: world_worker::options::max_lag is now
  seconds (cvc::kSimCatchup by default), max_lag_quanta() scales it with the
  leader's speed, and a value that is no catch-up is refused, so the world
  stays on the frame's thread.
- On the frame's thread (every single-threaded host, native or browser: arigl
  without the flag, the browser, snapshots, the headless AppRuntime), it is
  the catch-up one frame may run: SceneClockDriver sets the clock's stall
  guard from it when it binds (world_clock::set_max_steps_per_advance, new,
  which keeps the tick, and cap_scales_with_rate). Unset, the clock keeps the
  guard its host gave it, so no existing document changes.
- world_worker::available() is false in single-thread wasm. The worker tests
  skip there, and the browser's arigl says once that it steps the world on
  the frame's thread when given --world-thread.
- sim_tick.h: kSimCatchupMax, sim_catchup_valid, sim_catchup_quanta(_at), and
  sim_clock_config takes the catch-up.

Tests: WorldClockTest.TheStallGuardChangesInPlace,
SimTickTest.ACatchUpIsWholeQuantaAndGrowsWithTheSpeed,
AriadneScene.ClockBlockTakesAMaxLag,
AriadneSceneWorld.TheScenesMaxLagIsTheCatchUpAFrameMayRun and
AriadneWorldWorker.TheWorldMayTrailItsClockByMaxLag. Docs: ARIADNE.md
(--world-thread), WORLD_CLOCK_API.md, ARIADNE_WORLDS.md section 18.2.
@transfix
transfix enabled auto-merge (squash) November 23, 2026 03:49
# Conflicts:
#	inc/cvc/ariadne/scene_world.h
#	src/cvc/CMakeLists.txt
transfix added a commit that referenced this pull request Nov 23, 2026
The closed schema lands after the PRs that add loader keys, so it carries
their keys now:

- notifications: always, as well as a flag (#1450);
- a tray_icon's icon: and auth: (#1450);
- a color picker's fmt: rgb | hex (#1452);
- a load:'s name:, a key or an expression that names the application
  (#1485);
- scene: clock: max_lag:, more than 0 and at most 10 s, in the scene and
  in a scene of its own (#1475).

Master's own new keys need none: #1472's look: wheel:, wheelbase: and
track: sit in world:, which the world rules check, and #1399's region: is
a custom node's own key.

AcceptsWhatTheLoaderTakes takes each new form; FindsEachMistakeWhereItIs
finds fmt: cmyk and notifications: sometimes.
…1489)

Each world entity was a scene node of its own: a box look is six boxes and
a group, so 200 vehicles were 1400 actors. On arigl, 200 kinematic vehicles
at 3.6x took 61 ms a frame (19 of runtime, 42 to 46 of drawing), and 800
took seconds.

cvc::gl::ariadne::entity_view (entity_view.h) is the view of a set of
entities, whatever feeds it:
- set_entities (who each is: archetype, fleet, team, colours, look, size);
- promote, from the camera and the ids followed;
- then pose and draw each frame.

Its bodies layer draws the entities it takes as one mesh per archetype and
LOD rung:
- a fitted model gets four rungs (#1358's swarm rungs; decimate_mesh moves
  to mesh_lod.h and the swarm uses it there), a box look one;
- each copy is posed in 3-D, normals too, and culled on the frustum's
  sides. Near and far are left out: the renderer fits them to what it
  draws, and an unposed rung is a point, so a far plane fitted to it cut
  away the entities about to be drawn.

Promotion and layers:
- promote (8) are drawn as their own nodes by vehicle_view: the followed
  (a camera's track.target, vehicles.watch, the vehicle a client drives),
  then the nearest. An incumbent keeps its node until another is a fifth
  nearer.
- a layer of at most threshold (32) promotes them all, so small worlds
  look as before;
- type: entity_layer (of: all | { fleet } | { archetype } | { team }, lod:,
  promote:, threshold:) declares a layer. With none, an implicit layer
  covers every entity.

Two feeds, the local and the server-side holon:
- a scene's own world: update_entity_view in tick_scene. Poses come from the
  physics binding's group of the chassis bodies (bind_group), between steps,
  whether the frame steps the world or #1475's world_worker holon does;
- a relay's entities on a client: room_view::update_entities, from the
  entities section and the client's entity_playout poses.

sync_vehicle_markers draws only the promoted, and adds or removes nodes as
promotion changes. A boat, a mesh file look without fit, or an entity no
layer takes keeps its own node.

Test cvcgl_ariadne_entities (37 checks, 5 repeats): the implicit layer,
follow, keep, the threshold, of:, the world on a worker, and the room.
Locally, cvcgl_ariadne_labels, _scenes, _realize, _swarm, _physics and
cvcgl_room_view also pass.

arigl, 200 kinematic at 3.6x with --world-thread, alternating runs:
- 8 ms a frame (2.4 runtime, 5.4 to 6.6 drawing), against 61 with
  threshold: 100000 (each its own node);
- 800 take 8 ms of drawing. Their world, at 16 to 18 ms a frame, is now the
  cost.

Not yet: the other layers (flags, goals, trails, path, belief, dots,
targets, follow, headlights), of: { fleet } on a client (the room's
identities carry no fleet), and swarm_layer moving here (FL3).
# Conflicts:
#	src/cvc/CMakeLists.txt
#	src/cvc/ariadne/world_vehicles.cpp
#	src/cvcGL/ariadne/vehicle_view.cpp
#1471's parted look (look: { chassis:, wheel:, rig: }) is a fitted look whose
one-piece model is null, so the entity view drew every parted vehicle as a
node of its own.

- vehicle_look_mesh_of: a parted look's mesh is its chassis and its wheels
  at rest, each point where attach_parted_model's nodes draw it (the chassis
  fitted per axis; each wheel at its fitted hub, a right one turned or
  reflected as its rig says), the wheels in a tyre's dark. One texture, the
  chassis's. add_part bakes a part by a 3x3 matrix, normals by its inverse
  transpose; the one-piece model goes through it too.
- Role 3, the model's (white under its texture, else the entity's colour),
  so an untextured rung keeps role 2's dark.
- make_rungs decimates each colour role on its own. A coarse rung kept no
  roles, so the wheels would have taken the body's colour.
- sync_vehicle_markers keeps #1471's vehicle_wheels with the markers: a
  rebuild clears them, a demoted vehicle's go with its node.

Test cvcgl_ariadne_entities, parted: the mesh against attach_parted_model's
nodes (mirror turn and reflect, an axle offset); 40 at scale in the model's
four rungs, wheels dark at each rung drawn; one rung (lod: false), each
copy's chassis in its colour and its wheels dark.
@transfix
transfix disabled auto-merge November 23, 2026 21:10
@transfix
transfix enabled auto-merge (squash) November 23, 2026 21:10
@transfix transfix changed the title Fleets: kept fleet lookups, and D3 as OW7's first part (a drawn host's world on a worker, in a local holon) Fleets: kept fleet lookups, D3 as OW7's first part, and FL2's first part (a world's vehicles drawn at scale) Nov 23, 2026
transfix added a commit that referenced this pull request Nov 24, 2026
)

* Ariadne: a closed .ari schema every load checks, and ari validate

The .ari document's structure gets a formal definition, roadmap section 15,
now docs/ARIADNE.md section 14:

- src/cvc/ariadne/schema/ari.v1.schema.json: one JSON Schema for every
  top-level block, all 35 built-in widget types, the scene, include: and
  load: sites, with descriptions. Every map is closed: an unknown key is an
  error, except x- keys, a custom widget's or node's own keys, and a block an
  app registered or the document declares in customs:. A widget's type is its
  first type key in the loader's order. It keeps to json-schema-validator's
  draft-7 subset.
- CMake embeds it (CvcEmbedText.cmake) for ari_schema_json() and installs it
  under share/libcvc/ariadne/schema/.
- With the validator built in, every load checks the document, its import:ed
  libraries, its load: fragments and each include: expansion (placed in the
  unit's own file), as warnings and LoadResult::schema_issues with line and
  column. The compiled validators live in a cvc::app slot.
- validate_string / validate_file check without loading, the document's own
  units instantiated with their declared args.
- ari validate [--structural-only] [--strict] [--json] and ari schema.
- ci.yml: package-linux's configure assertion also requires the validator.

All 176 shipped documents are valid; reopen_refit.ari gains its missing
meta.min_libcvc. Five loader tests that feed bad values count the loader's own
warnings and check the schema flags the same pointer. New ariadne_schema_test
and ctests for ari validate and ari schema.

* Ariadne schema: scene: clock: hz, the world's rate

OW8 (#1441) gave the scene's clock an hz key: a whole number of ticks a
second from 10 to 240, as sim_rate_valid takes it. The schema takes it the
same way in both clock entries, and ClockBlockTakesAWorldsRate checks that the
schema accepts hz: 60 and flags each rate the loader warns about.

* Ariadne schema: the hosts' blocks in their short forms

wasm: takes a guest's path alone and relay: a relay's URL alone, as
their readers do; a bare server: or world: sets nothing, as theirs do.
The schema took a map only, so WasmWasiTest's `wasm: all.wat`, under
min_libcvc 3.7.13, failed its load on Linux.

* Ariadne schema: the keys the open PRs add to the loader

The closed schema lands after the PRs that add loader keys, so it carries
their keys now:

- notifications: always, as well as a flag (#1450);
- a tray_icon's icon: and auth: (#1450);
- a color picker's fmt: rgb | hex (#1452);
- a load:'s name:, a key or an expression that names the application
  (#1485);
- scene: clock: max_lag:, more than 0 and at most 10 s, in the scene and
  in a scene of its own (#1475).

Master's own new keys need none: #1472's look: wheel:, wheelbase: and
track: sit in world:, which the world rules check, and #1399's region: is
a custom node's own key.

AcceptsWhatTheLoaderTakes takes each new form; FindsEachMistakeWhereItIs
finds fmt: cmyk and notifications: sometimes.
CI's clang-format checks only the changed lines, so it would not align this
comment with the unchanged scene_labels.h line under it, while a whole-file
format does. Either spacing failed one of them; with no comment both agree.
# Conflicts:
#	src/cvc/CMakeLists.txt
@transfix
transfix merged commit 8fe7d4c into master Nov 24, 2026
2 of 27 checks passed
@transfix
transfix deleted the feat/d3-world-worker branch November 24, 2026 10:13
transfix added a commit that referenced this pull request Nov 24, 2026
# Conflicts:
#	src/cvc/CMakeLists.txt
transfix added a commit that referenced this pull request Nov 24, 2026
Conflict in ci.yml's arigl-web gate: master's #1476 runs it when the
clipboard changes, SH2 when how a viewport widget's view draws changes.
Both kept.
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