What exactly is WasmAllocator?

The documentation doesn’t really say a whole lot:

This is intended to be merged into GeneralPurposeAllocator at some point.

Is it an allocator that for some reason works better in WASM than the GPA?

The description is in std.heap.wasm_allocator

This allocator is fast, small, and specific to WebAssembly. In the future, this will be the implementation automatically selected by GeneralPurposeAllocator when compiling in ReleaseSmall mode for wasm32 and wasm64 architectures. Until then, it is available here to play with.

2 Likes

It’s past time to make that foreshadowed change - the compiler has been using this allocator when building from source for 1.5 years now, autodocs uses it since my rewrite, and I’ve been using it in a personal project. It’s tried and true at this point.

6 Likes

I second that Andrew. :+1:

Been using this wasm allocator in my current Zig/Wasm project, works great whereas the standard gpa allocator throws warnings and evetually assertion fails in some cases.

Auto selection refactor sounds neat, although it’s pretty nice to actually be able to pick that allocator manually. Fits the no hidden flow/stuff/make your own allocator Zig vibe.

So would be great to either merge or remove the “in the future” comment altogether yeah

1 Like

…just as a side note, in my home computer emulator project the ReleaseSmall mode is massively slower than both ReleaseFast and ReleaseSafe (about half the performance of both Fast and Safe).

When I checked the compiler output, this is because the compiler was aggressively outlining identical code snippets from a big switch-based CPU instruction decoder into function calls, and this totally destroyed performance.

E.g.: I’d still want to be able to use a small allocator on WASM even when not compiling with ReleaseSmall :slight_smile: In my code, allocator performance doesn’t matter (since I allocate only very infrequently, and mostly at startup), but code size does.

I guess even if gpa can do some smart or not so smart choice, you can always override that choice by actually using a WasmAllocator directly.

1 Like

Potentially helpful in the future:

1 Like