Sub-Microsecond Insect Agency in 92 KB of Cache
Simulating honeybee spatial learning, obstacle avoidance, and path integration in pure Rust without heap allocations.

2D headless arena simulation over 500,000 steps. Early exploratory random walk transitions into direct foraging vectors and path-integrated homing runs, reducing obstacle collisions by 98.5%.
Benchmarks
| Metric | Result |
|---|---|
| Throughput | 146,000 steps/sec (1 thread, commodity CPU) |
| Live memory | 92.4 KB (Agent 94,416 B, Sim 168 B) |
| Dynamic allocations | 0 in the simulation loop |
| Trajectory convergence | 758 steps/delivery (naive), 365 steps/delivery (converged) |
| Collision rate | 8,486 bumps/window (early), under 130 bumps/window (late) |
Architecture
Central Complex
Heading is held by a 32-unit continuous ring-attractor compass. Unit activity , with preferred angle , evolves as
which sustains one activity bump whose position encodes heading. Rotation shifts the bump by a fractional circular interpolation between neighboring units, so turns smaller than one unit do not quantize away:
Position is tracked by 2D dead reckoning. With decoded heading and speed , the home vector is
and homing steers along .
Mushroom Body
Sensory input is expanded by a sparse random projection onto 16,384 Kenyon cells. A 1.5% winner-take-all stage keeps about 246 of them, and the result is stored as a bitmask packed into [u64; 256] (2 KB), so later steps visit only active indices.
Learning is a local three-factor rule applied in place to weights from active cells onto output unit :
where is presynaptic activity, is an eligibility trace and is a scalar reward. Only active cells are updated, with no gradients and no stored history beyond .
Multi-Rate Execution
Compass integration, path integration and reflexes (obstacle avoidance) run every tick. The mushroom body’s associative evaluation runs every 8 ticks, and its output is held as a bias on the fast loop in between. Reflex latency therefore does not depend on the cost of the associative step, which is amortized over 8 steps.