Unofficial Hacker News companion — get notified on comment replies, and more.

The state of Rust allocators in 2026: stabilised (opens external site)

217 points by fanf2 4 days ago | cetra3.github.io | 90 comments on HN | Vote on HN (opens Hacker News) |

View full thread · View on Hacker News

Comment thread (22)

  1. > It's going to take a bit of time for the ecosystem to catch up to custom allocators.

    I havn't published any popular rust crate. I think my crates are downloaded by me and robots only, so I don't have a lot of authority. I have no wishes to think about custom memory allocators. I don't want them. I consider those as unnecessary complexity for a niche use case, and I'm a bit annoyed that they will pollute the Rust landscape. I understand why people need them though, but I fear that Rust is going to be the next C++: a bloated programming language with features to please everyone and a lack of simplicity. It's already complex enough.

    Replies (6)
    1. It already is bloated.

      I'm not saying it is a bad language as I use it since 9 years and still write new code in it.

      But if you compare writing an bump allocator in c or zig vs rust, it is comically bloated. Same applies to anything like a vector or a hashmap or anything else low level.

      You get a binary that is multiple megabytes if you just write a webserver on the path of least resistence.

      Replies (2)
      1. the Rust version of bcachefs has an object size 50% bigger than the C version, without trying to optimize for object size and with a whole bunch of new code to replace things that we used to get from the kernel but weren't Rust.

        Even if that doesn't shrink I consider that a very good tradeoff for what we're getting.

      2. May I ask if you're comparing apples to apples (statically linked everything) in the last case? I'm not very well versed in C or C++, but I do know that a common practice there is dynamically linking the world, so I'm curious if the size difference stays if you link statically in both cases?
        Replies (2)
        1. I write zig like C++ code where there is no headers (I use modules only) and I don't depend on libc or use any standard headers. The output binaries are extremely small if you also enable the linker garbage collection.

          So everything is statically linked and only depends on linux syscall API. It is not apples to apples compared to rust but you can't practically do that in rust anyway.

          Replies (1)
          1. What's stopping you? I do that on Windows; the trivial example of "add two numbers" is a 4kb DLL.

            You don't use the standard library, the equivalent of the kernel syscall API is there (the win32 API), and you have the ecosystem of no_std libraries available.

        2. Statically linking C code with glibc is more bloated than rust in my experience. However, using musl instead gives you binaries that easily fit in 10s of KB (compared to rust which I got to 300KB on stable without sacrificing the standard library)
    2. This isn't something baked into the core language like C++ features tend to be. This is standardization of library code, thoroughly vetting what people already had to do but in incompatible ways.

      This is the kind of work that is making Rust far easier and more productive for systems work, including even kernel development, than the bad old days of when every project was a monolith and everyone was reinventing the wheel.

      Over the past several months I've been converting bcachefs to Rust, and as part of that I have a whole truckload of code that I can now release as small self contained crates that anyone can use: safe RCU, an async runtime suitable for kernel IO paths, a fully lockless implementation of Cuckoo - custom allocators getting standardized is directly pertinent because now all that code (RCU, especially) will compose much better with other people's crates.

      Replies (1)
      1. > This isn't something baked into the core language like C++ features tend to be.

        Not much of C++ is baked into the core language, most of it is just the standard library, it includes custom allocators. If you look at libboost, it has always been some kind of a trial ground for future C++ versions, with the best parts ending into the standard, and it is just a library.

        Not so different from what is happening with Rust.

        Replies (1)
        1. C++ has new/delete as keywords, whereas allocation is purely a library concern in Rust.
          Replies (1)
          1. Which is one of the reasons, that unlike C++, Rust has the issue with allocate first on the stack, move into the heap afterwards, instead of directly allocating into the heap.
    3. As proven multiple times since JOVIAL, complex features are there for a reason.
      Replies (1)
      1. It's an art to decide which use cases should be denied or not.
        Replies (1)
        1. Sure, but “I don’t need it” isn’t the bar and features that aren’t paid for when not used are great since they stretch the language in an orthogonal direction that doesn’t represent any tradeoffs for anyone else
    4. Rust's async is 1000x more complicated than mere custom allocators, so the complexity argument is invalid. You are complaining about a mote of sand when there is a gigantic mammoth stomping on your head.
      Replies (1)
      1. Whataboutism.
        Replies (1)
        1. It is indeed a mote of sand that will actually simplify Rust libs. Arena or bump allocators can tie memory lifetimes to a scope/region, transforming complex ownership and object-lifetime problems into simpler region-lifetime problems.
          Replies (1)
          1. Can Rust’s borrow checker actually take notice of those transformations. I was not aware that using a bump allocator via the allocator API would allow for the static checks to reason about all intra-region allocations as a single entity.

            If you know where there is any information on the borrow checker’s ability to check ‘under’ an allocator Id love to read about their strategy.

            Replies (1)
            1. Yes, this is already possible and done in crates like bumpalo.
    5. > I have no wishes to think about custom memory allocators. I don't want them. I consider those as unnecessary complexity for a niche use case,

      Well, not to be rude, but Python and Go exist, you know. But if you're picking Rust (or Zig) — you will have to think about lifetimes, ownership, and allocations, that's the language's raison d'être.

      > with features to please everyone and a lack of simplicity.

      Like async! Compared to that barrel of worms, the new allocators are a complete non-issue. A two-functions trait, that Vec's and Box's "new_in" method use under the hood, with straightforward semantics — that's as complicated as having xmalloc()/xfree() in your C project.

      Replies (1)
      1. That’s rude.
    6. > I consider those as unnecessary complexity for a niche use case

      Custom allocators are certainly no niche use case, they are very common low level programming, from microcontrollers to audio software to video games.