It's all about the allocator
44 points by ibobev 5 days ago | 13 comments

KolmogorovComp 12 minutes ago
This is not an issue with Rust the language but with the standard library which assumes allocation is not a big deal.

Traditional where allocations matters, like for embedded devices you would use no-std.

An alternative standard library with a different focus is entirely possible.

Or as a middle ground a lint flagging allocations.

As an aside I believe the last ‘expect’ issue to triggers an existing clippy lint.

reply
krukah 2 hours ago
It's where Zig outshines Rust the most, IMO.

TBF Rust v1.100 makes a big leap in permitting custom allocators, but mandating would be ideal in the spirit of "explicit is better implicit". I like adding lints to defend against some of these footguns, but more compiler-driven transparency around quiet allocations would be so nice.

reply
daxfohl 3 hours ago
I knew it's not the point of the article, but would AI be any better at translating code to zig? Or would it make the same slow design, just with all the allocations being explicit?
reply
yeureka 5 hours ago
Bloomberg writes all of its C++ using an allocator aware version of the STL because of this issue. It’s open source and very high quality: https://github.com/bloomberg/bde
reply
ibobev 4 hours ago
What do you mean by "allocator-aware version of the STL"? The standard STL is also allocator-aware, and its containers have versions with a template allocator parameter and a polymorphic allocator.
reply
yeureka 4 hours ago
That is correct. However at Bloomberg all functions that potentially allocate memory have to have an allocator passed as an argument or use a local allocator since the BDE requires allocator parameters to always be passed, there are no default allocator arguments like in the STL.
reply
whorleater 2 hours ago
https://bloomberg.github.io/bde/white_papers/unleashing-aa-s...

lakos was one of the primary drivers of this

reply
denverllc 2 hours ago
Given how far allocators have come (like mimalloc or jemalloc) I would be interested to see if they make up some of the gap between the standard allocators (easy but not performant) and intrusive container allocators like in BDE
reply
fwlr 5 hours ago
Oh, wow, this is a fantastic explanation for why “Zig makes you pass the allocator around as an argument to all your functions” is A Good Thing, Actually. Kudos to the author!
reply
mac3n 2 hours ago
This argues for dynamically scoped variables - bindings that are scoped and inherited by all called functions without having to be passed explicitly. After all, why should everyone in the call chain need to know if some deep call allocates temporary storage.

It's always bothered me that the only such feature in many languages is exception handlers (I'm also bothereed by functions that throw things).

I want "late" bindings, implemented as "shallow" bindings. "Late" as in binding is established at runtime in the call chain. "Shallow" as in you don't need to crawl the call chain to find it. Something like

    extern Allocater *theAllocater = &DefaultAllocater;
    ...
    // allocater scope
    { Allocater *prev = theAllocater;
      theAllocater = NewAllocater();
      ...
      theAllocater->free();
      theAllocater = prev;
    }
with a deep call using the current allocater

    // deep call
    { tmp = theAllocater->alloc(size);
      ...
    }
reply
pdlclay 4 hours ago
[flagged]
reply
ngriffiths 4 hours ago
> So, if you want to write truly memory-efficient code, just asking AI to do it for you might not be enough.

In hindsight, it would be pretty funny if "hey can you rewrite this game in Rust" is sufficient instructions to end up with memory-efficient code. In fact it would be pretty funny if it were enough to get this thing written in Rust, for all the specific details of what you actually mean when you say "this game"

reply
alfiedotwtf 6 hours ago
“It’s all about the Pentiums, baby”
reply
ElUncivio 2 hours ago
[dead]
reply