The Flyweight
Minimize memory footprints by sharing as much data as possible with similar magical artifacts.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Conjuration // Efficiency
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
-- In Unison, all identical structures are automatically merged due to content-addressing.
-- The Flyweight pattern is natively provided by the weave itself!
structural type Particle = Particle Text
fireMote : Particle
fireMote = Particle "fire"
-- Creating a million fire motes simply references the same content hash in the Unison node.
summonSwarm : Nat -> [Particle]
summonSwarm n = List.fill n fireMote
The Flyweight pattern, an ancient technique for preserving the limited magical reserves (memory) of a wizard, is completely subsumed by Unison’s fundamental laws. Because all values are content-addressed and immutable, two identical spells share the same exact essence in the void. You may conjure a swarm of a million fire motes, and the weave will only store the true form once.
Runic Tags:
#structural
#flyweight
#unison
#content-addressed