From bf0164cdaf1e113aefca8a37c88181c44470ba90 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 16 Nov 2018 09:42:19 +0100 Subject: [PATCH] sstables: compress: Use libdeflate for crc32 Improves memtable flush performance by 10% in a CPU-bound case. Unlike the zlib implementation, libdeflate is optimized for modern CPUs. It utilizes the PCLMUL instruction. --- sstables/checksum_utils.hh | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/sstables/checksum_utils.hh b/sstables/checksum_utils.hh index c126a54088..6573406938 100644 --- a/sstables/checksum_utils.hh +++ b/sstables/checksum_utils.hh @@ -23,6 +23,7 @@ #include #include +#include "libdeflate/libdeflate.h" GCC6_CONCEPT( template @@ -85,6 +86,26 @@ struct zlib_crc32_checksummer { static constexpr bool prefer_combine() { return false; } // crc32_combine() is very slow }; +struct libdeflate_crc32_checksummer { + static uint32_t init_checksum() { + return 0; + } + + static uint32_t checksum(const char* input, size_t input_len) { + return checksum(init_checksum(), input, input_len); + } + + static uint32_t checksum(uint32_t prev, const char* input, size_t input_len) { + return libdeflate_crc32(prev, input, input_len); + } + + static uint32_t checksum_combine(uint32_t first, uint32_t second, size_t input_len2) { + return zlib_crc32_checksummer::checksum_combine(first, second, input_len2); + } + + static constexpr bool prefer_combine() { return false; } +}; + template inline uint32_t checksum_combine_or_feed(uint32_t first, uint32_t second, const char* input, size_t input_len) { if constexpr (Checksum::prefer_combine()) { @@ -94,4 +115,4 @@ inline uint32_t checksum_combine_or_feed(uint32_t first, uint32_t second, const } } -using crc32_utils = zlib_crc32_checksummer; +using crc32_utils = libdeflate_crc32_checksummer;