3 ms·
A possibly counterintuitive case where "the key...is expensive to compute" can be when accessing the key just requires following a pointer to something not in c
by twotwotwo 11y ago
A possibly counterintuitive case where "the key...is expensive to compute" can be when accessing the key just requires following a pointer to something not in cache. It's not the same thing syntactically, but, for example, Postgres sped up collation by packing bytes into integers:
http://pgeoghegan.blogspot.com/2015/01/abbreviated-keys-exploiting-locality-to.html http://pgeoghegan.blogspot.com/2015/01/abbreviated-keys-expl...
I've also seen speedups sorting strings by first sorting prefixes of them packed into uint64s (rather than sorting pointer/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.