Vec is asymmetric with memory handling

As someone who has been bitten badly by this, I don't agree with you that it's a bad default. As others have said, I think it's far more common to want the extra capacity to be there. It's somewhat rarer to need to care about excess capacity from a memory usage perspective. The aho-corasick example I linked is I think the only time this has been relevant to me (that I know about) in ten years of using Rust. In contrast, I've relied on excess capacity hanging around for "scratch buffer" use cases countless times.

The suggestion to "just have two different types" likely underestimates the effects that such designs have on decision paralysis, especially when it's as subtle as small tweaks to the capacity amortization trade-off. So I disagree that having two widespread types is "optimal."

16 Likes