Sigil 0.22.17
Sigil now manages its own memory allocator. Native programs built for static Linux x86_64 and C-to-WASM web builds use mimalloc 3.5.3 behind a new allocator interface, and the sigil command itself switches with them. Long-running programs hold much less memory, and web builds start smaller and grow less.
Existing projects build without changes. The first build after upgrading rebuilds each target's allocator once, because the allocator is now part of a build's cache identity.
Sigil manages its own allocator
Memory requests from Sigil's runtime and from bundled C code such as SQLite now go through one allocator interface that Sigil owns, instead of whatever the C library provides. On static Linux x86_64 builds and C-to-WASM web builds, that interface is backed by a pinned copy of mimalloc 3.5.3.
In our measurements, the allocator was the difference:
- A Slate server running for 15 minutes ended at about 125 MiB of resident memory, against 237 to 258 MiB with the previous allocator. The program's own live data was the same in every run; the difference was memory the old allocator kept but no longer used.
- Harkfell's web build started at 85 MiB of WASM memory instead of 100, and peaked at 177 to 201 MiB over a 15-minute session instead of 235 to
- WASM memory never shrinks, so a lower peak matters most on phones.
The shipped sigil command for Linux x86_64 is one of these static builds, so it uses mimalloc as well.
Web builds get tuned settings automatically
A default mimalloc reserves a large block of memory up front, which on the web made things worse, not better. C-to-WASM builds therefore get three compile-time settings automatically: MI_FREE_USE_PAGEMAP=1, MI_DEFAULT_ARENA_RESERVE=4096 and MI_ARENA_SLICE_SHIFT=14. They're upstream's own options, and the first is upstream's recommendation for WASI. You don't need to set anything.
Choosing the allocator
To keep the previous allocator for a build, add the allocator-stock feature:
(build name: 'web-stock target: "wasm32-wasi" features: '(release allocator-stock))
allocator-mimalloc requests mimalloc explicitly, and fails on a target where it isn't qualified yet. WASI builds can also pass typed MI_* settings; unknown names are rejected. Details are in the allocator guide.
The new sigil-allocator export from (sigil meta) reports which allocator a running program uses.
What stays the same
- Other native targets (Linux arm64, macOS, Windows, Android, the BSDs) keep their current allocator until each is qualified.
- Direct-WASM builds keep their own allocator.
- Garbage collection sizing and trimming are unchanged.
- The Zig SDK allocator fix from 0.22.16 stays in place wherever mimalloc isn't used.