Skip to main content

Memory and Persistence

A running Lyquid is a WASM module plus LyteMemory, the linear-memory layout behind Direct Memory Architecture (DMA). LyteMemory has three logical segments:

SegmentPurposeLifetimeVisibilityBacking store
VolatilePer-call scratch space and host I/O buffersone callcurrent call framenone
Networkdeterministic persistent stateacross calls and versionsall nodes at the same LyquidNumberversioned state store
Instancenode-local persistent stateacross callsone node's Lyquid instancesimple state store

The LDK exposes the layout boundaries as public constants:

ConstantValueMeaning
LYTESTACK_BASE0x30000000stack base used by Lyquid calls
LYTEMEM_BASE0x80000000base address of persistent LyteMemory
NETWORK_MEMSIZE_IN_MB1024network segment size
INSTANCE_MEMSIZE_IN_MB1024instance segment size
VOLATILE_MEMSIZE_IN_MB1024volatile segment size

The generated state! code routes each persistent allocation into the right segment (network or instance) and keeps those objects at stable guest addresses for the lifetime of the Lyquid, so your state behaves like ordinary long-lived Rust objects. You do not manage any of this directly — you declare state in state! and use it as normal Rust values.

Practical consequences:

  • persistent state behaves like normal Rust objects, but object address stability matters
  • memory growth is disabled for LyteMemory, so the segment sizes above are hard limits
  • network state is versioned through replay and dirty-page persistence
  • instance state is shared across cached execution objects on a node
  • an instance call at an older network version still sees current node-local instance state