Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sstable: reduce allocations during index flushing
While working on a separate change that included passing a large number of pre-generated blocks all to addIndexEntry in a tight loop, some of the allocations it was doing per block flushed became more apparent in profiles. By batch allocating keys used as separators, and by adjusting the buffering of filled sub-index blocks to store there finished byte representation (also batch allocated) and relevant details, rather than the whole block writer used for that sub-index block, that blockWriter can instead be reused, which importantly allows reuse of its allocated buffers for things like restarts, eliminating a significant source of allocations for when flushing many sub-index blocks. ``` name old time/op new time/op delta Writer/block=4.0_K/filter=false/compression=NoCompression-10 50.4ms ± 0% 50.4ms ± 1% ~ (p=0.730 n=4+5) Writer/block=4.0_K/filter=false/compression=Snappy-10 62.6ms ± 2% 62.1ms ± 1% ~ (p=0.222 n=5+5) Writer/block=32_K/filter=false/compression=NoCompression-10 48.1ms ± 0% 48.5ms ± 0% +0.73% (p=0.008 n=5+5) Writer/block=32_K/filter=false/compression=Snappy-10 59.0ms ± 3% 58.1ms ± 2% ~ (p=0.690 n=5+5) name old speed new speed delta Writer/block=4.0_K/filter=false/compression=NoCompression-10 759MB/s ± 0% 759MB/s ± 1% ~ (p=0.730 n=4+5) Writer/block=4.0_K/filter=false/compression=Snappy-10 156MB/s ± 2% 157MB/s ± 1% ~ (p=0.222 n=5+5) Writer/block=32_K/filter=false/compression=NoCompression-10 785MB/s ± 0% 779MB/s ± 0% -0.73% (p=0.008 n=5+5) Writer/block=32_K/filter=false/compression=Snappy-10 115MB/s ± 3% 117MB/s ± 2% ~ (p=0.690 n=5+5) name old alloc/op new alloc/op delta Writer/block=4.0_K/filter=false/compression=NoCompression-10 1.18MB ± 0% 0.80MB ± 0% -32.14% (p=0.008 n=5+5) Writer/block=4.0_K/filter=false/compression=Snappy-10 1.20MB ± 0% 0.83MB ± 0% -31.08% (p=0.008 n=5+5) Writer/block=32_K/filter=false/compression=NoCompression-10 252kB ± 0% 952kB ± 0% +278.63% (p=0.008 n=5+5) Writer/block=32_K/filter=false/compression=Snappy-10 456kB ± 0% 1157kB ± 0% +153.58% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Writer/block=4.0_K/filter=false/compression=NoCompression-10 10.7k ± 0% 0.1k ± 0% -99.03% (p=0.008 n=5+5) Writer/block=4.0_K/filter=false/compression=Snappy-10 10.7k ± 0% 0.1k ± 0% -98.97% (p=0.008 n=5+5) Writer/block=32_K/filter=false/compression=NoCompression-10 1.27k ± 0% 0.10k ± 0% ~ (p=0.079 n=4+5) Writer/block=32_K/filter=false/compression=Snappy-10 1.27k ± 0% 0.10k ± 0% -91.84% (p=0.008 n=5+5) ```
- Loading branch information