A possibly counterintuitive case where &quot;the key...is expensive to compute&quot; can be when accessing the key just requires following a pointer to something not in cache. It&#x27;s not the same thing syntactically, but, for example, Postgres sped up collation by packing bytes into integers:<p><a href="http:&#x2F;&#x2F;pgeoghegan.blogspot.com&#x2F;2015&#x2F;01&#x2F;abbreviated-keys-exploiting-locality-to.html" rel="nofollow">http:&#x2F;&#x2F;pgeoghegan.blogspot.com&#x2F;2015&#x2F;01&#x2F;abbreviated-keys-expl...</a><p>I&#x27;ve also seen speedups sorting strings by first sorting prefixes of them packed into uint64s (rather than sorting pointer&#x2F;length references to string data), and in an application where a friend needed to sort a lot of indices into an array, it turned out to greatly speed the sort (by avoiding indirections) to copy the whole array, sort the indices and the copy of the array together, then toss out the copy.