Unofficial Hacker News client - receive Push Notifications on replies.

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

182 points by fanf2 2 days ago | cetra3.github.io | 73 comments on HN | Vote on HN (opens Hacker News)

View full thread · View on Hacker News

Comment thread (3)

  1. This is a bit of a misunderstanding. Using a bump allocator is also useful for avoiding things like SmallVec. It can also good for reducing page faults or using the CPU cache better.

    It has a lot of applications but people just don't use it for those applications.

    It is just difficult to understand why people use it unless you actually understand what effects it has. I think a lot of people are making the mistake of assuming they would have realized the need for it naturally, but it is pretty hard to just stumble into it as an idea.

    I understood the importance because of writing storage engines in rust for some years where I had a lot of trouble avoiding memory fragmentation with global allocators and also having page faults destroying performance. Even then you don't immediately think "oh I should use a bump allocator", you would still need to understand how the design of that allocator effects the problems you have.

    Replies (1)
    1. A SmallVec and the SSO types I've spent more time thinking about seem like poor use cases for an Allocator mechanism.

      After some thought, the best use case I could come up with was as follows: a set of K growable arrays such that in total they have M entries but each might have N = 0..=M entries of its own and so with SmallVec that needs K*M space but with an Allocator you're sure it all fits in M space which may be a significant improvement.

      Except I think the correct representation for that is a single Boxed array or similar and K slices of that Boxed array instead.

      Replies (1)
      1. The way I use it is to have a more long lived bump allocator and a "temporary" bump allotor which I regularly roll back to some earlier offset.

        If a function doesn't know the size it needs for a vector for example. It will at least have an upper bound, then it can allocate with the upper bound on the temporary alloc and construct the thing. After it is constructed it gets moved to the more long lived allocator. So the program is really only accessing three sections of memory at a time including the stack. Allocation/deallocation are just integer increment/decrement. And I can put an upper bound on the amount of memory a section of the program will use.

        This way you don't need the SSO types at all.