from Hacker News

Talc – A fast and flexible allocator for no_std and WebAssembly

by excsn on 2/29/24, 1:22 AM with 27 comments

  • by tekacs on 2/29/24, 2:41 AM

    I've been using this recently in WASM, in particular for the counters feature. It's really great and it makes it super easy to track and follow the evolution of your app's memory!

    In my console, I have something akin to this:

      TRACE client_wasm::plugins::allocation: Memory stats counters=Counters { allocation_count: 165454, total_allocation_count: 18756119, allocated_bytes: 34654828, total_allocated_bytes: 3185258585, available_bytes: 82802636, fragment_count: 5026, heap_count: 1, total_heap_count: 1, claimed_bytes: 118423552, total_claimed_bytes: 118423552 }
    
    I haven't carefully benchmarked dlmalloc (Rust's default WASM allocator, https://github.com/alexcrichton/dlmalloc-rs), but it's nothing special (to my knowledge). The swap to Talc is pretty trivial and it's clear that the author is paying attention to its performance.
  • by speps on 2/29/24, 3:31 AM

    Added a new issue [1] to add TLSF to the benchmarks as it's likely going to be faster in a single-threaded environment according to the rlsf crate [2].

    [1] https://github.com/SFBdragon/talc/issues/26 [2] https://github.com/yvt/rlsf

  • by lasiotus on 2/29/24, 5:04 PM

    Some extra context for comparison: Talc is faster than Frusa when there is no contention, but slower when there are concurrent allocations. Both are much slower than Rust's system allocator. Benchmark here: https://crates.io/crates/frusa.
  • by gleenn on 2/29/24, 1:48 AM

    As a guy who lives in the JVM most days and mostly ignores allocation optimizations, what are some examples of things that are actually newer features in such a project? Isn't allocation a mostly solved problem? Is something about WebAssembly or no_std actually requiring different features?
  • by weinzierl on 2/29/24, 10:23 AM

    Why isn't it benchmarked against the vanilla glibc allocator? Is it similar enough to dlmalloc that the differences don't matter?
  • by caleb-allen on 2/29/24, 2:25 PM

    Pardon my ignorance, but is this something that a language with a GC could potentially use to run in a WebAssembly environment?