Stream: wasm

Topic: Better global allocator for Rust compiled to wasm


view this post on Zulip Benjamin Bouvier (Jan 25 2022 at 17:38):

I was looking for good global_allocator replacements, for use in Rust code compiled to wasm. Wee-alloc seems to optimize for its own code size, and not for performance. Are there any other known good replacements that would be usable in Rust targeting wasm?

view this post on Zulip Benjamin Bouvier (Jan 25 2022 at 17:39):

There are crates for tcmalloc / mimalloc crates on crates.io, which are all bindings to the C implementation, so that doesn't seem to be viable when compiling to wasm.

view this post on Zulip Dan Gohman (Jan 25 2022 at 17:39):

dlmalloc is the other major one I know about.

view this post on Zulip Benjamin Bouvier (Jan 25 2022 at 17:42):

Thanks, I'll try that!

view this post on Zulip Alex Crichton (Jan 25 2022 at 17:54):

I believe though the Rust-default allocator is dlmalloc, so using the crate manually probably won't have much of an impact

view this post on Zulip Alex Crichton (Jan 25 2022 at 17:54):

I'm not actually personally aware of any compiled-to-wasm allocators other than dlmalloc and wee_alloc at the moment

view this post on Zulip fitzgen (he/him) (Jan 26 2022 at 16:59):

emscripten has a couple too, but it might be a bit of a build nightmare linking them into Rust

view this post on Zulip fitzgen (he/him) (Jan 26 2022 at 17:00):

I had dreams of making a wee_alloc 2.0 that actually had decent performance, rather than just really good code size, and wrote https://github.com/fitzgen/intrusive_splay_tree towards that goal, but then never actually wrote an allocator using that. @Benjamin Bouvier maybe you can pick up the torch :)

An intrusive splay tree implementation that is no-std compatible and free from allocation and moves - GitHub - fitzgen/intrusive_splay_tree: An intrusive splay tree implementation that is no-std co...

view this post on Zulip Stephan Renatus (Jan 26 2022 at 17:01):

https://github.com/wingo/walloc

A small malloc implementation, for use in WebAssembly - GitHub - wingo/walloc: A small malloc implementation, for use in WebAssembly

view this post on Zulip fitzgen (he/him) (Jan 26 2022 at 17:02):

ah yes I forgot about that one. I think it is also aimed at small code size, rather than performance, so might not be what bnjbvr is looking for

view this post on Zulip Stephan Renatus (Jan 26 2022 at 17:09):

also not a crate. sorry, just a tangent.

view this post on Zulip theduke (Mar 18 2022 at 18:49):

I have had the same concerns. I think allocation-heavy workloads suffer quite a lot at the moment.

mimalloc is pretty small, has good performance and actually supports wasm!
I don't think the current mimalloc wrapper crates support it though, so there's probably some build/linking tinkgering required.

mimalloc is a compact general purpose allocator with excellent performance. - GitHub - microsoft/mimalloc: mimalloc is a compact general purpose allocator with excellent performance.

Last updated: Nov 26 2024 at 00:12 UTC