https://stackoverflow.com/questions/5200338/a-cache-efficien...
But note that robko made an improvement even before making that.
Or maybe not: my short experiments with the simplified version based on their algorithm and his JavaScript versions gave some conflicting results. I haven't thoroughly verified them, this note is just to motivate the others to try.