pub struct Scratch<T: Packable> { /* private fields */ }Expand description
The buffer pack_with and unpack_with transpose through, kept so it can be reused.
Going between row order and the transposed layout needs somewhere to put the other order, and
that somewhere is VALUES values, which is 8 KB for a u64. Allocating it per call is not the
expensive part. Zeroing it is, because the allocator hands back a page it has to clear and the
transpose then writes every element of it anyway. On a scan of a packed integer column that is
once per 1024 rows, and it showed up as the largest single item in a ClickBench profile, larger
than the unpacking it was making room for.
So a caller that unpacks more than one unit should make one of these and pass it in.
It starts empty and grows on the first unit that needs it, because a caller holds one for a whole decode and most chunks are not bit packed at all. Making the buffer in the constructor was tried and was worse than what it replaced, by more than the zeroing it saved.