The Flyweight: Shared Leyline Echoes
Minimizing mana footprint by sharing state across millions of fine-grained spell instances.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Transmutation // Memory-Weaving
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module Flyweight
import Data.Vect
-- The intrinsic, shared state
record RuneCore where
constructor MkRuneCore
sigil : String
baseCost : Nat
-- The extrinsic, unique state
record CastInstance where
constructor MkCastInstance
core : RuneCore
coordinates : (Double, Double)
-- A shared cache of cores
fireCore : RuneCore
fireCore = MkRuneCore "Ignis" 50
iceCore : RuneCore
iceCore = MkRuneCore "Glacies" 40
spawnStorm : Nat -> RuneCore -> List CastInstance
spawnStorm n c = replicate n (MkCastInstance c (0.0, 0.0))
When an archmage summons a storm of a thousand blades, maintaining the arcane geometry for each blade individually would shatter the mind. The Flyweight separates the intrinsic essence (RuneCore) from the extrinsic coordinates. By sharing references to pure, immutable RuneCore records, the memory weave remains pristine. The Theorem Proving Pacts ensure that these shared nodes remain immutable and eternally valid.
Runic Tags:
#structural
#optimization
#state-sharing