{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreidx25kr7kim4fagikwda34ar7bi35whj35s2vtvuryhdbtoplwvte",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mkra5aumsf42"
  },
  "path": "/t/could-collections-hypothetically-store-keys-and-values-inline/24195#post_20",
  "publishedAt": "2026-05-01T03:15:33.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "This is true, you could do this, but if you have fixed inline size for structs and you're not doing \"small map optimization\" then this is somewhere in the 48 to 24 bytes of wasted space (depending on what exactly you know) per map. Further, if you merely do things like putting all the keys and values in a single bucket, your code is liable to still end up pointlessly hashing the key.\n\nHowever, this is all besides the point, which is that regardless of whether this is a thing that you could do (yes, though presumably with at least a bit of overhead), I don't believe any notable implementation of a hash map actually does (afaict, even JavaScript—which is the most optimized of the \"everything's a hashmap\" dynamic languages and has JIT-compilation for maps with consistent key sets—doesn't seem to have anything in particular for handling small maps in general).\n\nSure, in some sense this is a self-perpetuating problem—if hash maps weren't suboptimal for small sets then people would be used to using them for that in performant code and there'd be pressure to do these optimizations—but it really doesn't seem worth the complexity when people can just choose the appropriate data structure for their use case. If somebody should be trailblazing this optimization, it's languages like Go or Python or JavaScript, not Rust.\n\nRust has much worse performance footguns for much more common use-cases than \"don't use a HashMap when the expect size is 4 pairs if you care about performance\" and expects programmers to be knowledgable enough to avoid them.\n\nFor example, Rust is the only major programming language I'm aware of not to buffer file IO in its default standard library implementation (even C's `fread`/`fwrite` are buffered by default!). I don't think this is a flaw in Rust, it's just part of a philosophy that making the default behavior simple and predictable is more important than making it optimized for all plausible use cases.",
  "title": "Could collections hypothetically store keys and values inline?"
}