Zippy level 2 for denser compression and faster decompression

We also increased the hashtable size by 1 bit as it significantly degraded the ratio. Thus even level 1 might slightly improve.

PiperOrigin-RevId: 621456036
This commit is contained in:
Snappy Team
2024-04-03 09:40:00 +00:00
committed by Danila Kutenin
parent 4f5cf9a8d6
commit 766d24c95e
5 changed files with 309 additions and 50 deletions

View File

@@ -50,13 +50,33 @@ namespace snappy {
class Source;
class Sink;
struct CompressionOptions {
// Compression level.
// Level 1 is the fastest
// Level 2 is a little slower but provides better compression. Level 2 is
// **EXPERIMENTAL** for the time being. It might happen that we decide to
// fall back to level 1 in the future.
// Levels 3+ are currently not supported. We plan to support levels up to
// 9 in the future.
// If you played with other compression algorithms, level 1 is equivalent to
// fast mode (level 1) of LZ4, level 2 is equivalent to LZ4's level 2 mode
// and compresses somewhere around zstd:-3 and zstd:-2 but generally with
// faster decompression speeds than snappy:1 and zstd:-3.
int level = DefaultCompressionLevel();
static constexpr int MinCompressionLevel() { return 1; }
static constexpr int MaxCompressionLevel() { return 2; }
static constexpr int DefaultCompressionLevel() { return 1; }
};
// ------------------------------------------------------------------------
// Generic compression/decompression routines.
// ------------------------------------------------------------------------
// Compress the bytes read from "*source" and append to "*sink". Return the
// Compress the bytes read from "*reader" and append to "*writer". Return the
// number of bytes written.
size_t Compress(Source* source, Sink* sink);
size_t Compress(Source* reader, Sink* writer,
CompressionOptions options = {});
// Find the uncompressed length of the given stream, as given by the header.
// Note that the true length could deviate from this; the stream could e.g.
@@ -76,14 +96,15 @@ namespace snappy {
//
// REQUIRES: "input[]" is not an alias of "*compressed".
size_t Compress(const char* input, size_t input_length,
std::string* compressed);
std::string* compressed, CompressionOptions options = {});
// Same as `Compress` above but taking an `iovec` array as input. Note that
// this function preprocesses the inputs to compute the sum of
// `iov[0..iov_cnt-1].iov_len` before reading. To avoid this, use
// `RawCompressFromIOVec` below.
size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
std::string* compressed);
std::string* compressed,
CompressionOptions options = {});
// Decompresses "compressed[0..compressed_length-1]" to "*uncompressed".
// Original contents of "*uncompressed" are lost.
@@ -126,16 +147,15 @@ namespace snappy {
// RawCompress(input, input_length, output, &output_length);
// ... Process(output, output_length) ...
// delete [] output;
void RawCompress(const char* input,
size_t input_length,
char* compressed,
size_t* compressed_length);
void RawCompress(const char* input, size_t input_length, char* compressed,
size_t* compressed_length, CompressionOptions options = {});
// Same as `RawCompress` above but taking an `iovec` array as input. Note that
// `uncompressed_length` is the total number of bytes to be read from the
// elements of `iov` (_not_ the number of elements in `iov`).
void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
char* compressed, size_t* compressed_length);
char* compressed, size_t* compressed_length,
CompressionOptions options = {});
// Given data in "compressed[0..compressed_length-1]" generated by
// calling the Snappy::Compress routine, this routine
@@ -215,7 +235,7 @@ namespace snappy {
static constexpr int kMinHashTableBits = 8;
static constexpr size_t kMinHashTableSize = 1 << kMinHashTableBits;
static constexpr int kMaxHashTableBits = 14;
static constexpr int kMaxHashTableBits = 15;
static constexpr size_t kMaxHashTableSize = 1 << kMaxHashTableBits;
} // end namespace snappy