GithubHelp home page GithubHelp logo

shnatsel / rust-lz-fear Goto Github PK

View Code? Open in Web Editor NEW

This project forked from main--/rust-lz-fear

0.0 2.0 0.0 407 KB

A fast pure-rust no-unsafe implementation of LZ4 compression and decompression

License: MIT License

Rust 100.00%

rust-lz-fear's Introduction

lz-fear

This crate aims to implement the LZ4 compression and decompression algorithm, as well as the framing format used for LZ4 files, in pure Rust with no unsafe code. The output perfectly matches the C reference implementation byte for byte. At the time of writing, this is also the fastest no-unsafe implementation that I'm aware of.

The lz4 crate calls into the C library. The compress crate has an implementation that relies on unsafe. And the redox implementation (more on that below) is slower, in some cases substantially.

Decompressor status: Beta. Works well, and is blazingly fast (at least as fast as the official C implementation in my tests).

Compressor status: Alpha. You can expect it to produce perfect (i.e. identical to what the C library produces) output for all configurations. Non-default block sizes are an exception here, not entirely sure what the problem is. Dictionary is also implemented slightly differently right now. There is one other unknown edge case where output differs slightly. Note that all of these cases still produce valid and correct output, they just encode slightly differently than the C implementation (compression ration may be slightly worse in these cases). The API may still change a little. The example named "dolz4" is a compressor but is currently lacking a CLI. You have to configure it by changing the code. Performance is good, but takes ~2-3x as long as the C implementation. The current bottleneck appears to be an abundance of range checks when writing output (~25% of cycles spent in there) which also cause the compiler to completely trip over itself and sometimes emit a sequence of copy_from_slice calls for 1-byte and 4-byte writes to the output array. Help wanted.

If you take a look at the git history, this is strictly speaking a fork from @johannesvollmer. He took redox-os' lz4 compression, and reworked it to be usable as a library crate.

However after noticing performance issues, I have gradually rewritten both the compressor and the decompressor from scratch to closely resemble the 2400-line mess that is the official C implementation (and that's just the raw format without framing!). Admittedly they pack plenty of optimizations in there (lots of intentionally reading beyond buffer boundaries for the sake of performance), but I'm proud to say that I achieved similar performance in just 400 lines of competely safe Rust.

Code Fuzzing

Fuzzing requires a nightly toolchain. Fuzzing for this project is currently confirmed to work with:

rustc 1.44.0-nightly (f509b26a7 2020-03-18)

Running

cargo install cargo-fuzz
cargo +nightly fuzz run roundtrip_fuzz

rust-lz-fear's People

Contributors

bschwind avatar johannesvollmer avatar main-- avatar shnatsel avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.