It's all about the allocator

ibobev 62 points 17 comments November 15, 2026
aarol.dev · View on Hacker News

Discussion Highlights (8 comments)

alfiedotwtf

“It’s all about the Pentiums, baby”

fwlr

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!

yeureka

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

ngriffiths

> 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"

daxfohl

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?

krukah

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.

KolmogorovComp

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.

Panzerschrek

I don't think it's that necessary to return back to manual memory management (Zig-style) and abandoning proper RAII (Rust-style) to spare some memory. With a little bit effort it's possible to achieve good memory efficiency without sacrificing safety (by manually managing allocators). Chromium-based applications consume so much memory, not because they don't use manual memory management, but because JS used for application code isn't nearly as efficient in memory usage as any other proper language. Also the browser engine itself is optimized in such a way, that it sacrifices memory usage to gain more speed.

Semantic search powered by Rivestack pgvector
3,874 stories · 35,194 chunks indexed