acdream/tests/AcDream.App.Tests/Streaming
Erik 39967e78bd perf #418: parallelize landblock builds across a striped worker pool
Login publishes the 25x25 window at a flat 32 blocks/s (~27 s in the
tunnel). The reveal-timing probe A/B (695a27b4) showed the consumer
budget env ceilings change nothing, which was read as producer-limited:
one "acdream.streaming.worker" thread, ~31 ms/block. This replaces the
single worker with min(ProcessorCount-2, 8) workers, floor 1.

Design: striped/affinity dispatch. Each worker owns one unbounded lane
channel plus its own high/low priority queues; jobs route to
lane = ((id >> 16) * 2654435761) % N (the low word of a landblock id is
constant, so the id is mixed before reduction). Striping was chosen
over a shared queue + in-flight conflict tracker because it preserves
the per-landblock contract structurally rather than by bookkeeping:
every job for one id lives on one lane, so per-id enqueue order IS
execution and completion-arrival order, and the same-landblock
supersede rules (PromoteToNear removes queued LoadFar/Unload) keep
seeing every queued job for that id. Contract, point by point:

- Per-landblock ordering: same id -> same lane -> serial FIFO.
- ClearLoads: broadcast to every lane inside the same _inboxGate lock
  that serializes enqueues, so any load enqueued before
  ClearPendingLoads() returns sits ahead of its lane's ClearLoads copy
  in that lane's FIFO and is dropped at read time, exactly like the
  single-thread path. Already-dequeued builds still complete (now up
  to one per worker instead of one total); StreamingController's
  SweepCollapsed already unloads those uniformly.
- Priority: per-lane high/low split unchanged. Cross-lane, priority is
  not globally ordered (a lane cannot run another lane's job), which
  the contract permits; near-tier jobs hash-spread across lanes and
  are preferred within each.
- Outbox: SingleWriter flipped to false; nothing assumed single-writer
  (PublishResult already used TryWrite + an Interlocked backlog, and
  the consumer's peek->read head-stability holds because only the
  single reader ever moves the head). Cross-landblock arrival order
  was verified arbitrary-tolerant before relying on it:
  StreamingController.AdmitCompletions classifies each result
  independently into per-priority FIFOs (generation staleness +
  per-landblock retirement blocking); per-landblock arrival order is
  preserved by striping.
- Crash surface: per-worker. The first real crash publishes
  WorkerCrashed (prefixed "worker N:" in pools > 1), sets
  _workerFailure, completes every lane, and cancels the pool (a crash
  still ends all processing, as before); siblings that merely observe
  the closed lanes (ChannelClosedException) exit quietly instead of
  reporting spurious crashes; the outbox completes only when the LAST
  worker exits so no in-flight completions are dropped.
- Disposal: joins every worker under the same _disposeGate; Start
  stays idempotent and dispose-serialized.

Thread-safety audit of the production build closures
(SessionPlayerComposition), per shared object:

- DatCollection (every read in LandblockBuildFactory.BuildLocked:
  LandblockLoader.Load, SceneryGenerator.Generate, SetupMesh.Flatten,
  CellMesh.Build, GfxObjBounds.Get, GfxObjDegradeResolver): NOT
  thread-safe; already serialized under the shared _datLock, which
  BuildLocked holds for the whole read transaction. Unchanged; the
  probe run measured hold 0-13 ms / wait <= 12 ms during the login
  window, so the lock is not the new bottleneck and the build was NOT
  serialized beyond it.
- PakPreparedAssetSource / PakReader (BuildPreparedCollisionClosure,
  outside the lock): immutable TOC array + read-only
  MemoryMappedViewAccessor random-access reads + ConcurrentDictionary
  verdict caches - safe for N concurrent readers (Slice I3 design;
  the headless SharedPreparedCollisionCache wrapper is fully
  lock-protected).
- LandblockMesh.Build (outside the lock): pure math over the dat
  record + the composition-time height table + the immutable
  TerrainBlendingContext record; the shared SurfaceCache is a
  ConcurrentDictionary and BuildSurface is deterministic, so its
  lookup-or-build race is last-write-wins-benign (the code already
  documented exactly this).
- PhysicsDiagnostics probe statics: read-only bools + thread-safe
  Console writes.

MEASURED OUTCOME (gate 4): the timing acceptance did NOT pass, and per
the task contract that is reported, not tuned around. With 8 workers
on this 16-core machine all 625 builds complete in ~203 ms
(ACDREAM_PROBE_TELEPORT BUILD lines t=3475390..3475593) - the producer
is off the critical path - but loaded= still advances at exactly
+32/1000 ms and SUMMARY totalMs measured 27395 and 27503 across two
runs (baseline 26728). The 32/s pacer is in the consumer
admission/publication path and is not governed by the
StreamingWorkBudgetOptions env ceilings. #418 stays IN-PROGRESS on the
consumer side; see docs/ISSUES.md for the evidence chain.

Tests: per-landblock ordering under 4-worker contention, cross-lane
ClearLoads drop, per-lane near-before-far preference, pool-of-1 serial
equivalence, disposal joining every worker, lane-spread guard, and
worker-count validation (LandblockStreamerPoolTests). Two existing
tests asserted a GLOBAL cross-landblock execution order - a serial
implementation detail, not the contract - and now pin workerCount: 1
with justification comments (LoadNear_OvertakesQueuedFarLoads,
TwoQueuedLoads_RetainTheirDistinctOriginAndGeneration).

Gates: Release build 0 errors; App suite 5575 passed / 3 skipped
(5568 + 7 new); Runtime suite 1756/0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 19:34:20 +02:00
..
GpuWorldStateActivatorTests.cs refactor(streaming): compose landblock presentation transaction 2026-07-21 21:45:16 +02:00
GpuWorldStateAnimatedIndexTests.cs fix(rendering): bound portal resource lifetime 2026-07-18 21:35:16 +02:00
GpuWorldStateCollisionResidencyTests.cs refactor(physics): remove parsed collision graphs 2026-07-25 18:21:19 +02:00
GpuWorldStateRenderTraversalTests.cs test(app): put every strict-zero site on the probe (#250) 2026-07-29 03:49:13 +02:00
GpuWorldStateVisibilityTests.cs fix(streaming): stop replaying committed recenter retirements 2026-08-02 20:53:11 +02:00
GraphicalRemotePlacementServiceWindowTests.cs feat(physics): C4 route 4b-1 — remote placement infrastructure (dormant) 2026-08-04 04:08:19 +02:00
LandblockBuildFactoryTests.cs refactor(physics): remove parsed collision graphs 2026-07-25 18:21:19 +02:00
LandblockBuildOriginTests.cs perf #418: parallelize landblock builds across a striped worker pool 2026-08-17 19:34:20 +02:00
LandblockConcretePresentationPipelineTests.cs refactor(runtime): own per-session physics simulation 2026-07-26 13:39:57 +02:00
LandblockPhysicsPublisherTests.cs fix(physics): S2 — static publication emits authored Spheres as Spheres (AP-155 narrowed) 2026-08-07 08:07:02 +02:00
LandblockPresentationPipelineTests.cs fix(streaming): stop replaying committed recenter retirements 2026-08-02 20:53:11 +02:00
LandblockRenderPublisherTests.cs perf(streaming): cursor publication across frame budgets 2026-07-24 19:10:18 +02:00
LandblockRetirementCoordinatorTests.cs fix(streaming): stop replaying committed recenter retirements 2026-08-02 20:53:11 +02:00
LandblockStaticPresentationPublisherTests.cs refactor(runtime): own per-session physics simulation 2026-07-26 13:39:57 +02:00
LandblockStreamerPoolTests.cs perf #418: parallelize landblock builds across a striped worker pool 2026-08-17 19:34:20 +02:00
LocalPlayerTeleportControllerTests.cs feat(session): the in-world logoff — LogOut animation, reverse wormhole, live return to character select 2026-08-17 14:02:40 +02:00
RuntimeTeleportDestinationAdapterTests.cs refactor(runtime): own teleport destination correlation 2026-07-26 17:52:34 +02:00
StreamingCompletionQueueTests.cs fix(streaming): preserve portal destination ownership 2026-07-25 08:35:12 +02:00
StreamingControllerReadinessTests.cs fix(test): cover the atlas-tier seam the D-1 fix depends on; correct AP-150's citation 2026-08-06 07:54:03 +02:00
StreamingFrameControllerTests.cs refactor(physics): delete legacy PhysicsEngine.Resolve/ResolvePlacement/HasCellSurface (C5a, AP-1/AD-1) 2026-08-05 14:11:31 +02:00
StreamingWorkBudgetTests.cs fix(streaming): preserve portal destination ownership 2026-07-25 08:35:12 +02:00
TeleportLandblockTransitionTests.cs fix(world): remove non-retail portal exit fade 2026-07-15 23:20:52 +02:00
WorldGenerationQuiescenceTests.cs refactor(runtime): acknowledge exact world host projections 2026-07-26 18:27:41 +02:00
WorldRevealCoordinatorTests.cs fix(streaming): derive the portal reveal window from the live streaming radii (#280) 2026-08-05 23:54:59 +02:00
WorldRevealDerivedWindowIntegrationTests.cs fix(streaming): make a demoted landblock render-ready like a published one (#280 D-1) 2026-08-06 07:27:28 +02:00
WorldRevealReadinessBarrierTests.cs fix(streaming): make a demoted landblock render-ready like a published one (#280 D-1) 2026-08-06 07:27:28 +02:00