RAII Based Memory Management Can Be a Bottleneck For Performance?

92 points omagdy7 31 comments

So I stumbled on this article I think it's a good read and definitely made me question things and more curious which is always a good thing. Aside from the first part of the article which talks about Linux kernel drama I don't care about that part for this discussion, but rather the Idea that RAII based memory management which rust adopts heavily makes it so that your program ends up calling malloc and free possibly thousands or millions of times based on how big your code is. So the author seems to suggest(he also links to another video by casey mutori that talks about this stuff) that due to how RAII works it makes it hard to batch your allocations of similar lifetimes and deallocate them all at once.

So I am no expert and never really had to write an application where I needed to think about performance this deeply and probably 99% of applications won't be affected by RAII based memory management, but from my limited experience wouldn't you in rust be able to just use Arena allocator to solve that problem? or even you could always venture and write your absolute performance critical part of your application in unsafe rust which will you give as much freedom if you were to write it in C or Zig.

Why does the author seems to disregard that unsafe rust exists and from my limited research Arena allocators are possible in rust

Thought I'd ask here to get more expert answers or point me to a blog that maybe talks about this.