Could collections hypothetically store keys and values inline?
ais523:
you can go even further and just embed the capacity directly into bits of the pointer by allocating it an appropriate address. This makes reading the capacity potentially faster than with the pointer/capacity/length layout, because you don't actually have to read the capacity from memory, just use a few masks and shifts.
You can do this in your own code, and build a CompactVec that is two words rather than three (if you are okay with small vecs only, or with capacities that must be power of two, or other restriction like that, it could even be just one word). Then, whenever you need to actually use the Vec, you build it on the stack and call any method. This is sound exactly because the stdlib documented the layout of a Vec (you just have to use ownership to prevent doing this twice).
Maybe that won't be faster but if you have a large number of Vecs stored somewhere, it might make sense, idk.
Discussion in the ATmosphere