Persistent stores

pub fn store_persist_copy(r: const reference, path: text) -> boolean fs#update

Write an image of r to path, laid out for PAGING, and keep the live collection as it is. Use this to save a collection and for a file another program (or a browser) will READ — a vocabulary, a map, any shipped dataset — where what matters is how few pages a query touches.

The image is a rebuilt copy, with each record placed in its collection's own order — key order for a trie — so one prefix is one run of pages. Records in the live store sit where they were INSERTED; written as they are, a 20-record prefix query on a 74,692-word vocabulary read 22 requests and 1.25 MB, against 4 and 0.26 MB from the rebuilt image.

The live collection is untouched: nothing moves, so every reference you hold stays valid, and writes after this do not reach the file. Write it again to save a later state; store_load reads it back. words: trie<Word[w]> = [] for w in vocabulary() { words += [Word { w: w }] } store_persist_copy(words, "vocab.store") // ship this file // a reader pages it: store_load_prefix(local, "vocab.store", "kerk", 20)

A reference<T> to a record in the same collection is carried: it names the same record in the image. Returns false on an I/O or format error, and for a collection the image cannot carry — one holding a reference into another store. The image is sized to its content, with none of the growth slack the live store keeps. Beside it goes its layout (<path>.dschema). A guard (<path>.guard, the SHA-256 of both files) is not written here: whoever wants one writes it, and a load then says when the file differs from the one it was written for.

pub fn store_load(r: reference, path: text) -> boolean fs#read

Load a persisted store IMAGE fully into memory, populating the empty store-rooted collection r so it can be queried like any in-memory collection — the reading counterpart of store_persist_copy. It copies the file into memory, so it works on EVERY backend, wasm included, and writes after it stay in memory: write the collection again with store_persist_copy to save them. A file whose .dschema records an older layout than r's declared type is converted in memory: every added field takes its default (which may read the record through $), and the file itself is left as it is. Returns false on a missing / truncated / wrong-format file, and on a change the conversion cannot carry, such as one that looks like a rename (no panic; the reason is printed on stderr). Before it adopts the file it walks the record numbers and lengths inside it (the walk store_verify runs), so a crafted, corrupt or changed file cannot send a read outside its own data: it is refused (false, the reason on stderr). A guard beside the file that does not match it is reported on stderr and the file is read all the same — the walk still holds. To know a file is the one its publisher wrote, load it by store_load_url with its SHA-256 pin. This is the whole-file load that the browser's working-set path builds on. h: hash<Rec[id]> = [] store_load(h, "world.store") // h now holds the file's records

pub struct Release { pub major: integer, pub minor: integer, pub patch: integer }

A release number, major.minor.patch: what a store records as the release of the program that wrote it, and what an upgrade routine is told its stored data came from. Releases are ordered by number, so 10.0 comes after 9.0, and a text compares as the release it spells: fn upgrade(from: Release, old: ItemBefore2, item: Item) { if from < "2.0" { item.count = len(old.label) } }

pub operator compare(self: Release, other: Release) -> Ordering

Releases in the order they were made: by major, then minor, then patch.

pub operator compare(self: Release, other: text) -> Ordering

A release against the release a text spells ("2", "2.1", "2.1.3"; a part that is missing or not a number counts as 0): from < "2.0".

pub operator to_text(self: Release) -> text

major.minor.patch.

pub fn store_load_url(r: reference, url: text, sha256: text, schema_sha256: text = "") -> boolean fs#read

Load a persisted store IMAGE over HTTP(S) from a TRUSTED source, establishing authenticity BEFORE the bytes are adopted: fetch the whole image at url, verify its SHA-256 against the caller-pinned sha256 (lowercase hex), and only on a match heap-load it into r — the bytes never touch disk. A fetch error or a hash mismatch REFUSES the load (returns false, loads nothing). The fetch→verify→trust discipline the registry install uses, bridged onto the store loader; url may be http(s):// or file://. Like store_load, it refuses an image whose <url>.dschema records a different layout than r's type, and an image with no .dschema at all. Whole-file counterpart of the paged store_load_key(s)/store_load_range loaders. schema_sha256 pins that .dschema too: the layout file decides how the pinned bytes are read, so whoever can change it on the host (or on the path, for http://) can change what the image means. Given, a sidecar whose SHA-256 differs, or that is missing, refuses the load; left out, the sidecar is read unpinned, as before. Pin both for a source you do not control (shasum -a 256 world.store world.store.dschema gives the two). h: hash<Rec[id]> = [] store_load_url(h, "https://cdn.example/world.store", "<sha256-hex>", "<dschema-sha256-hex>")

pub fn store_load_url_trusted(r: reference, url: text) -> boolean fs#read

Load a whole store IMAGE over HTTP(S)/file:// from a TRUSTED source into r — the INSTANT counterpart of store_load_url: skips the SHA-256 pin (you trust the origin) for a fast read, but is still structurally validated, so a corrupt or malformed image is rejected (false), never adopted, and an image whose <url>.dschema records a different layout is refused. Use store_load_url for an untrusted source. world: hash<Rec[id]> = [] store_load_url_trusted(world, "https://cdn.internal/world.store")

pub fn store_verify(r: const reference) -> boolean

Structural integrity check of a store-rooted collection's heap graph: verify every internal pointer targets a live record — no dangling / out-of-bounds / cyclic edge. Returns true when sound, false (with a reason on stderr) when not. The verifier behind the working-set loader's confidence: after any store_load*, store_verify(local) proves the (partial) copy produced a structurally valid heap, not one with a pointer left aimed at the source. h: hash<Rec[id]> = [] store_load_key(h, "block.store", 42) assert(store_verify(h)) // the load produced a sound heap

pub fn store_reclaim(r: reference) -> integer fs#update

Give back the free space at the END of a store-rooted collection's store, and return the BYTES handed back to the allocator (0 when there was nothing to give). Records are never moved, so every reference into the collection stays valid.

You say when, because only the program knows whether a drop is permanent: a collection that shrinks and grows again would just pay to re-grow. Read store_memory() first, and read it as a RANKING rather than a quantity: its tail% says which store is worth reclaiming, and it is NOT the size of the return. A reclaimed store lands at tail 11% — a growth reserve the allocator keeps — so what comes back is tail% - 11% of the resulting capacity, never the whole tail. Measured across eight shapes with tails from 13% to 60%: at a 13% tail the report suggests ~36 KB and the call hands back 5832 bytes. Treat a reading near 11% as nothing to get back, not a little. Its inner% is the space BETWEEN records, which this does not touch — though the number RISES after a reclaim, because the capacity it is a percentage of has shrunk.

WHERE the drop was matters as much as how big it was. mergeable counts adjacent free neighbours that never coalesced, so it measures how CONTIGUOUS the drop was, and that is exactly the part this call can fix: the same 2000 records dropped contiguously merge 2004 free blocks down to 7 and hand back 25400 bytes, while dropped alternately they leave 1997 blocks standing forever — the live records between them are what keeps them apart — and hand back 16312.

You do NOT need this before writing an image: store_persist_copy writes the collection rebuilt, sized by what it holds. Call it MID-RUN, when a live set has dropped for good and the memory is wanted back before the end. // …a region of the world is unloaded for good… store_reclaim(world) // the store follows what the world holds NOW Returns 0, changing nothing, for a store that is read-only or shares another store's memory.