News for hackers. Stuff that matters.
Re:Box to Save Memory in Rust by VorpalWay on Monday April 27, 2026 @11:31AM (#47922953)
Storing the length in the allocation has potential performance tradeoffs too! The most obvious is that taking a substring/string view will need a copy (or use a different type that store the length outside the allocation).

But it also means the CPU has to follow the pointer (and potentially get a cache miss or pipeline stall) to find the length. Having a fat pointer of ptr+length makes a lot of sense for string views, and for owned string buffers with capacity it can mean avoiding a cache miss when appending to the buffer.

It's complicated in other words.

There are no comments on this comment yet.