Why is Rust so Liberal with Heap Allocations?

258 points philogy 113 comments

Ever since learning about data oriented design and the potential cost associated with system calls and trying to apply it more to my own code I've noticed that in "idiomatic Rust" it's quite common to model data as nested trees of enums with Box, Vec & String. While this is a super intuitive way to model data it's not always the most efficient.

For a language that prides itself for performance I rarely see libraries leverage alternative allocators such as arenas or other advanced data packing strategies when I peak under the hood of libraries.

Is this just a situation of focusing on readability & correctness first and avoiding premature optimization or is there something deeper going on here? Curious what your guys' perspective is.