Skip to content

perf: SIMD heightfield math and zone idle throttling - #69

Open
clouths wants to merge 6 commits into
linux+containerizefrom
perf/simd-heightfield-idle-throttling
Open

clouths wants to merge 6 commits into
linux+containerizefrom
perf/simd-heightfield-idle-throttling

Conversation

@clouths

@clouths clouths commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Server-side performance work split out of #5 to keep that PR scoped to Linux support and test automation. Single commit on top of linux+containerize.

Contents

  • SimdMath (src/Perpetuum/Simd/) — SIMD-accelerated heightfield math
  • HeightfieldMetadata + CompactPassabilityMask — per-chunk height bounds / passability masks maintained incrementally from terrain updates
  • LineOfSight — heightfield precheck before the tile walk
  • Zone — idle throttling when a zone has no active work; TerrainUpdateMonitor tracks dirty chunks
  • compose — GC adaptation env for the server container

Unit tests: SimdMathTests, CompactPassabilityMaskTests, HeightfieldMetadataTests, ZoneHeightfieldTests, ZoneIdleThrottlingTests (22 tests).

Dynamic plant changes

Plants express height and solidity in the Blocks layer (TerrainExtensions.PutPlant / ClearPlantBlocking set BlockingInfo.Plant + Height on growth/harvest), so plant state changes flow through TerrainUpdateMonitor → Heightfield.MarkDirtyTile/MarkDirtyArea like any other terrain mutation.

Using the #idlethrottle admin command

Switches the throttle on a live server (no restart) via the standard admin chat command system:

#secure                 <- once; secures the channel (required)
#idlethrottle,false     <- disable throttling (CPU baseline)
#idlethrottle,true      <- re-enable (no argument also means enable)
#unsecure               <- when done

Notes: the sending character must have AccessLevel.admin (the router's existing exact-equality check, value 14); the switch is global (all zones); every # command is logged to adminCommandLog.

Open review items (from #5, apply to this code)

  • Idle throttling currently drops UpdateUnits(time) for NPC-only zones — breaks NPC time accumulation (PBS energy, timers, expiry). Reviewer suggested elapsed-time accounting; not yet applied.
  • Idle interval 1 s → 250 ms per reviewer feedback; not yet applied.

Validation

Server-side performance work, split out from the Linux/containerization
branch to keep that PR scoped to platform support and test automation.

- SimdMath (src/Perpetuum/Simd): SIMD-accelerated heightfield math
- HeightfieldMetadata + CompactPassabilityMask: per-tile height and
  passability metadata maintained from terrain updates
- LineOfSight: heightfield precheck before the tile walk
- Zone: idle throttling when a zone has no active work
- TerrainUpdateMonitor: dirty-chunk tracking
- compose: GC adaptation env for the server container
- unit tests: SimdMath, CompactPassabilityMask, HeightfieldMetadata,
  ZoneHeightfield, ZoneIdleThrottling
@clouths clouths self-assigned this Sep 28, 2026
@clouths
clouths added this pull request to stack #70 September 28, 2026 16:59
The test called Monitor.Enter and then awaited while holding the lock;
continuations reschedule onto the thread pool, so Monitor.Exit could run
on a different thread and throw SynchronizationLockException (observed
in CI). A dedicated holder thread now owns the monitor for the
observation window; the test body awaits as before.
Server-side performance work, split out from the Linux/containerization
branch to keep that PR scoped to platform support and test automation.

- SimdMath (src/Perpetuum/Simd): SIMD-accelerated heightfield math
- HeightfieldMetadata + CompactPassabilityMask: per-tile height and
  passability metadata maintained from terrain updates
- LineOfSight: heightfield precheck before the tile walk
- Zone: idle throttling when a zone has no active work
- TerrainUpdateMonitor: dirty-chunk tracking
- compose: GC adaptation env for the server container
- unit tests: SimdMath, CompactPassabilityMask, HeightfieldMetadata,
  ZoneHeightfield, ZoneIdleThrottling
@clouths
clouths force-pushed the perf/simd-heightfield-idle-throttling branch from 217b961 to b8b8081 Compare September 28, 2026 17:25
…enPerpetuum/PerpetuumServer2 into perf/simd-heightfield-idle-throttling
Runtime on/off switch for the zone idle throttle so its CPU savings
can be measured on a live server without a restart.

- ZoneIdleThrottling: volatile on/off flag (default on), read on the
  zone tick thread, written by the command handler
- Zone.Update: idle throttling applies only while the flag is set
- zoneIdleThrottleSet: GameAdmin channel command (state 1 = on,
  0 = off), registered next to the other channel commands, replies
  with the resulting state
- test: throttle off updates units every tick at full tick time,
  re-enabling resumes once-per-idle-second with accumulated elapsed
The vanilla client reaches admin channel commands through the chat
command router (messages starting with # in a secured channel), not as
raw request commands. Replace the zoneIdleThrottleSet request command
and handler with a [ChatCommand("IdleThrottle")] in
AdminCommandHandlers, matching how the other channel commands work.

- #idlethrottle[,true|false] in a #secure'd channel toggles
  ZoneIdleThrottling on the live server; replies with the new state
- tests: command parsing/application and router gating (command does
  not run in an unsecured channel); both flag-mutating test classes
  moved into the serial PerpetuumStaticsCollection
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