SAVANNA ENGINE

Ultra-scale spatial lattice engine — 107 billion cells simulated on one laptop

The Numbers

MetricValue
Peak simulation107,374,182,400 cells (100 billion)
HardwareApple M5 Max, 128 GB unified memory
100B wall time122 minutes (2 hours, 100 tiles)
Peak GCUPS15.8 billion cell-updates/sec
TPS at 1M cells1,722 ticks/sec
GPU compute at 1B2.7s per tick (GPU only)
Recording size (100B)500 GB (5 frames × 100 tiles)
Memory layoutMorton Z-curve (2.11× at 1B vs row-major)
Grid init (cached)0.01s (was 30s — Immortal Grid)
State init (GPU)3.8ms (was 30s — genesis.metal)

For Everyone

You're watching a digital Serengeti. Green is grass. Dark patches are where zebra herds have eaten everything bare. Blue pools are watering holes. White dots are zebras. Red dots are lion prides.

The zebras travel in herds of thousands, eating grass as they go. When they've stripped an area, they move on — the grass slowly grows back behind them, creating fractal grazing boundaries that look like coastlines viewed from space.

Each red dot is a pride of four lionesses. They hunt together, following zebra scent across the landscape. One kill feeds the entire pride and produces eight cubs. Cubs stay with the pride until it reaches eight adults, then the young ones split off to form a new pride.

Pinch to zoom. Time scales with space: zoom in to watch a single hunt, zoom out to watch centuries of evolution at 8,000× speed.

For the Curious

This is a Lotka-Volterra predator-prey system, but spatial — not equations on a chalkboard. Each animal is an autonomous agent with three senses (hearing, sight, smell) and a facing direction. Herding, hunting, and migration all emerge from local rules. Nobody tells the zebras to form herds — they align their movement with neighbors (Vicsek flocking) and it happens.

Every animal has a ternary metabolic state: active (+1), resting (0), or refractory (-1). Active costs energy. For zebras, refractory means panic. For lions, it means torpor — zero energy burn, drifting like a ghost until it smells prey.

The zoom is spacetime. Fifteen Lévy-scaled tiers from 1× to 8,000×. At the microscale you watch individual cells. At the macroscale you watch population waves. Same physics, different resolution. The scaling exponent is α=1.5 (Lévy superdiffusion — because predators use Lévy flights, not Brownian motion).

Water creates metapopulation structure. Randomly generated lakes form habitat patches. Animals cluster near water, creating high-density zones connected by grassland corridors. The ecosystem is a network of oases.

For Engineers

GPU Pipeline

13 Metal kernel dispatches per tick: 4 scent diffusions (Float32, all cells), 7 entity updates (one per color group, ~1/7 of cells each), 1 grass growth, 1 census. The hex grid uses 7-coloring: (col + row + 4*(col&1)) % 7 — distance-2 safe (Molloy & Salavatipour 2005). Zero atomics in the entity pipeline.

Morton Z-Curve

All GPU buffers use Morton-ordered memory. Bit-interleaving maps (col, row) to a space-filling curve where spatial neighbors are close in memory. At 1 billion cells, Morton is 2.11× faster than row-major because scent diffusion reads 6 neighbors per cell — 4 kernels per tick. Cache line utilization jumps from ~30% to ~80%. Interactive benchmark charts.

Gemini Optimizations (4/4 implemented)

OptimizationBeforeAfter
A. Immortal Grid (cache HexGrid to disk)30s/tile0.01s
B. genesis.metal (GPU state init)30s/tile3.8ms
C. Async Frame Writes (GCD overlap)Sync blocked~2× I/O overlap
D. Halo Protocol (ghost zones)Invisible walls3-cell read-only halos

CPU overhead per tile collapsed from 60 seconds to 14 milliseconds (4,286×).

Pride Dynamics

One red dot = one pride (4 lionesses). Per-species energy budgets: zebra max 500, lion max 8,000 (pride). One kill = 8,000 energy → exactly 8 cubs (4 lionesses × 2 each). Cubs born with staggered ages (uniform reproductive phase) for constant birth flow. Prides attract up to 8, then adults split. Lions follow zebra scent; no lion-scent tracking (prevents ant-trail artifacts).

RG-LOD (Renormalization Group Level-of-Detail)

GPU mipmap pyramid: reduce_lod_compose converts entity buffer to composition vectors (grass/zebra/lion/water fractions per pixel). reduce_lod_cascade halves resolution repeatedly. render_lod blends entity colors by fraction — 0.01% lions show as faint red tint over green, not solid red blocks. The renormalization operator applied to rendering.

Tiled Architecture (100B+)

World = N×N tiles, each 1B cells (32768×32768). Tiles simulated sequentially, one GPU-load at a time. Grid topology cached (41 GB binary — loads in 1s vs 30s rebuild). Async frame writes overlap GPU compute and disk I/O. Halo Protocol: 3-cell ghost zones around tile perimeters for cross-boundary scent diffusion and animal sensing.

Qwen Coder Debug Session

The full Metal shader (800+ lines) was sent to Qwen3 Coder Next via LM Studio for automated bug detection. Found 3 bugs including a critical negative-energy reproduction overflow. Gemma 4 31B hallucinated on the same input.

Acknowledgments

Carlos Mateo MuñozDelta Compression for Dynamic HTML (MIT License). Carlos's dictionary-based Brotli delta compression (RFC 9842 extension) is the architecture for real-time streaming of tiled simulation playback. Between ticks, ~5% of cells change — delta compression reduces frame updates from gigabytes to megabytes. Carlos, if you're reading this: we hit 100 billion cells. Your delta architecture is the last piece for streaming it live. See you at lunch.

Gemini Deep Think — Architectural review and the four optimization directives (Immortal Grid, genesis.metal, Double-Buffer Pipeline, Halo Protocol) that eliminated 99.97% of CPU overhead.

Built by Norayr Matevosyan with Claude (Anthropic). Apple M5 Max, 128 GB unified memory.
Engine: Swift + Metal. Viewer: vanilla HTML/JS. No frameworks, no cloud, no clusters.
Source on GitHub — GPL v3.

← Back to Savanna