Skip to content

Commit 94771a1

Browse files
committed
Use fast decompression in deflate_bytes.
This commit changes the parameters of `deflate` to do faster, lower-quality compression. For the compression of LLVM bytecode -- which is the main use of `deflate_bytes` -- it makes compression almost twice as fast while the size of the compressed files is only ~2% worse.
1 parent feefe77 commit 94771a1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/libflate/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@ extern "C" {
9494
-> *mut c_void;
9595
}
9696

97-
const LZ_NORM: c_int = 0x80; // LZ with 128 probes, "normal"
97+
const LZ_FAST: c_int = 0x01; // LZ with 1 probe, "fast"
98+
const TDEFL_GREEDY_PARSING_FLAG: c_int = 0x04000; // fast greedy parsing instead of lazy parsing
9899

99-
/// Compress a buffer without writing any sort of header on the output.
100+
/// Compress a buffer without writing any sort of header on the output. Fast
101+
/// compression is used because it is almost twice as fast as default
102+
/// compression and the compression ratio is only marginally worse.
100103
pub fn deflate_bytes(bytes: &[u8]) -> Bytes {
101-
let flags = LZ_NORM;
104+
let flags = LZ_FAST | TDEFL_GREEDY_PARSING_FLAG;
102105
unsafe {
103106
let mut outsz: size_t = 0;
104107
let res = tdefl_compress_mem_to_heap(bytes.as_ptr() as *const _,

0 commit comments

Comments
 (0)