• Stars
    star
    435
  • Rank 100,085 (Top 2 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fastest pure Rust implementation of LZ4 compression/decompression.

Rust Docs Crates.io

lz4_flex

lz4_flex_logo

Fastest LZ4 implementation in Rust. Originally based on redox-os' lz4 compression, but now a complete rewrite. The results in the table are from a benchmark in this project (66Kb JSON, 10MB dickens) with the block format.

AMD Ryzen 7 5900HX, rustc 1.69.0 (84c898d65 2023-04-16), Manjaro, CPU Boost Disabled, CPU Governor: Performance

66Kb JSON

Compressor Compression Decompression Ratio
lz4_flex unsafe w. unchecked_decode 1615 MiB/s 5973 MiB/s 0.2284
lz4_flex unsafe 1615 MiB/s 5512 MiB/s 0.2284
lz4_flex safe 1272 MiB/s 4540 MiB/s 0.2284
lzzz (lz4 1.9.3) 1469 MiB/s 5313 MiB/s 0.2283
lz4_fear 662 MiB/s 939 MiB/s 0.2283
snap 1452 MiB/s 1649 MiB/s 0.2242

10 Mb dickens

Compressor Compression Decompression Ratio
lz4_flex unsafe w. unchecked_decode 347 MiB/s 3168 MiB/s 0.6372
lz4_flex unsafe 347 MiB/s 2734 MiB/s 0.6372
lz4_flex safe 259 MiB/s 2338 MiB/s 0.6372
lzzz (lz4 1.9.3) 324 MiB/s 2759 MiB/s 0.6372
lz4_fear 201 MiB/s 370 MiB/s 0.6372
snap 286 MiB/s 679 MiB/s 0.6276

Features

  • Very good logo
  • LZ4 Block format
  • LZ4 Frame format (thanks @arthurprs)
  • High performance
  • 1,5s clean release build time
  • Feature flags to configure safe/unsafe code usage
  • no-std support with block format (thanks @coolreader18)
  • 32-bit support

Usage:

Compression and decompression uses no usafe via the default feature flags "safe-encode" and "safe-decode". If you need more performance you can disable them (e.g. with no-default-features).

Safe:

lz4_flex = { version = "0.11" }

Performance:

lz4_flex = { version = "0.11", default-features = false }

Block Format

The block format is only valid for smaller data chunks as as block is de/compressed in memory. For larger data use the frame format, which consists of multiple blocks.

use lz4_flex::block::{compress_prepend_size, decompress_size_prepended};

fn main(){
    let input: &[u8] = b"Hello people, what's up?";
    let compressed = compress_prepend_size(input);
    let uncompressed = decompress_size_prepended(&compressed).unwrap();
    assert_eq!(input, uncompressed);
}

no_std support

no_std support is currently only for the block format, since the frame format uses std::io::Write, which is not available in core.

Benchmarks

The benchmark is run with criterion, the test files are in the benches folder.

Currently 4 implementations are compared, this one, lz-fear, the c version via rust bindings and snappy. The lz4-flex version is tested with the feature flags safe-decode and safe-encode switched on and off.

Tested on AMD Ryzen 7 5900HX, rustc 1.69.0 (84c898d65 2023-04-16), Manjaro, CPU Boost Disabled, CPU 3GHZ

Results v0.11.0 02-06-2023 (safe-decode and safe-encode off)

cargo bench --no-default-features

Compress

Decompress

Results v0.11.0 02-06-2023 (safe-decode and safe-encode on)

cargo bench

Compress

Decompress

Miri

Miri can be used to find issues related to incorrect unsafe usage:

MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-disable-stacked-borrows" cargo +nightly miri test --no-default-features --features frame

Fuzzer

This fuzz target generates corrupted data for the decompressor. cargo +nightly fuzz run fuzz_decomp_corrupt_block and cargo +nightly fuzz run fuzz_decomp_corrupt_frame

This fuzz target asserts that a compression and decompression rountrip returns the original input. cargo +nightly fuzz run fuzz_roundtrip and cargo +nightly fuzz run fuzz_roundtrip_frame

This fuzz target asserts compression with cpp and decompression with lz4_flex returns the original input. cargo +nightly fuzz run fuzz_roundtrip_cpp_compress

Bindings in other languages

TODO

  • High compression

Migrate from v0.10 to v0.11.1

To migrate, just remove the checked-decode feature flag if you used it.

More Repositories

1

ts-dependency-graph

prints a dependency graph in dot/mermaid format for your typescript/react project
TypeScript
174
star
2

yamaha-nodejs

A node module to control your yamaha receiver
JavaScript
121
star
3

serde_json_borrow

Fast JSON deserialization on borrowed data
Rust
70
star
4

wana_kana_rust

Utility library for checking and converting between Japanese characters - Hiragana, Katakana - and Romaji
Rust
55
star
5

toml-to-json-online-converter

toml to json and json to toml online converter - written in rust compiled to wasm
HTML
29
star
6

binggan

Benchmarking library for stable Rust
Rust
25
star
7

rust_measure_time

measures and prints wall time in rust for given scope
Rust
14
star
8

veloci

High performance fulltext search engine
Rust
10
star
9

cool-id-generator

Rust
7
star
10

lz4-wasm

https://pseitz.github.io/lz4-wasm/
JavaScript
7
star
11

bench_riddle

Repo To Blogpost https://quickwit.io/blog/performance-investigation
Rust
4
star
12

japanese-dictionary

JavaScript
3
star
13

HomeAutomation.js

JavaScript
3
star
14

future_cache

async cache that caches futures and their results in rust
Rust
3
star
15

germansynonyms

uses openthesaurus and nodejs to find german synonyms
JavaScript
3
star
16

chinese

HTML
2
star
17

chemtrailsimulator

JavaScript
2
star
18

rust_simplex_noise

Rust
2
star
19

GitAliases

Just some useful git aliases
Shell
2
star
20

tantivy_bench_graph

regression tracking for tantivy benchmarks
JavaScript
2
star
21

reddit-api-node

2
star
22

quickcalc

A spotlight like calculator based on iced
Rust
1
star
23

easystarts

typescript port of easystarjs
JavaScript
1
star
24

node-hdbconnect

hana database driver for node - wraps hdbconnect
Rust
1
star
25

stay_focused

C
1
star
26

vint32_rust

fast vint u32 encoding for rust
Rust
1
star
27

fastcpy

fastcpy
Rust
1
star
28

rust_string_hashmap

Rust
1
star
29

Sublime-Keymap

1
star
30

masterofcellion

JavaScript
1
star
31

watcher

watch files, copy git stage
JavaScript
1
star
32

DHCP-Broadcast-Callback

Lets you register a callback for received DHCP Callbacks with the MAC adress of the issuing device.
JavaScript
1
star
33

sort_and_fragmentation

small experiment to measure memory fragmentation on sort speed
Rust
1
star
34

Custom-Highlighter

Highlights text for any ruleset
JavaScript
1
star
35

rappable

JavaScript
1
star
36

diskbased_json_array

file based random access json array
JavaScript
1
star
37

fst_compression

Rust
1
star
38

SoundOnReturn

Plays sound on a yamaha receiver, when mobile phone connects with wlan
JavaScript
1
star
39

quantile_compare

quantile_compare
Rust
1
star
40

tocfl

chinese TOCFL vocabulary by levels
Rust
1
star
41

kanji_hanzi_converter

Translate Japanese Kanji to Chinese Hanzi
Rust
1
star
42

peakmem-alloc

Measure the peak memory consumption of a given scope in rust
Rust
1
star
43

test_serde_formats

test_serde_formats
Rust
1
star