LZ4 (compression algorithm)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
LZ4 (compression algorithm)
Original author(s) Yann Collet
Developer(s) Yann Collet
Initial release April 24, 2011 (2011-04-24)
Stable release r129 / May 7, 2015; 21 days ago (2015-05-07)
Development status Active
Written in C
Operating system Cross-platform
Platform Portable
Type Data compression
License New BSD
Website https://github.com/Cyan4973/lz4/

LZ4 is a lossless data compression algorithm that is focused on compression and decompression speed. It belongs to the LZ77 family of byte-oriented compression schemes.

Features[edit]

The algorithm gives a slightly worse compression ratio than the LZO algorithm – which in turn is worse than algorithms like gzip. However, compression speeds are similar to LZO and several times faster than gzip while decompression speeds can be significantly faster than LZO.[1]

Design[edit]

The LZ4 algorithm represents the data as a series of sequences. Each sequence begins with a one byte token that is broken into two 4 bit fields. The first field represents the number of literal bytes that are to be copied to the output. The second field represents the number of bytes to copy from the already decoded output buffer (with 0 representing the minimum match length of 4 bytes). A value of 15 in either of the bitfields indicates that the length is larger and there is an extra byte of data that is to be added to the length. A value of 255 in these extra bytes indicates that yet another byte to be added. Hence arbitrary lengths are represented by a series of extra bytes containing the value 255. The string of literals comes after the token and any extra bytes needed to indicate string length. This is followed by an offset that indicates how far back in the output buffer to begin copying. The extra bytes (if any) of the match-length come at the end of the sequence.[2]

Compression can be carried out in a stream or in blocks. Higher compression ratios can be achieved by investing more effort in finding the best matches. This results in both a smaller file and a faster decompression.

Implementation[edit]

The reference implementation in C by Yann Collet is licensed under a BSD license. There are ports and bindings in various languages like Java, C#, Python etc.[3] Databases like Hadoop use this algorithm for fast compression. LZ4 was also implemented natively in the Linux kernel 3.11.[4] The FreeBSD, Illumos, ZFS on Linux, and ZFS-OSX implementations of the ZFS filesystem support the LZ4 algorithm for on-the-fly compression.[5][6][7][8] Linux supports LZ4 for Squashfs since 3.19-rc1.[9]

References[edit]

  1. ^ "[Phoronix] Support For Compressing The Linux Kernel With LZ4". Phoronix.com. Retrieved 30 November 2014. 
  2. ^ Yann Collet. "RealTime Data Compression". Fastcompression.blogspot.in. Retrieved 30 November 2014. 
  3. ^ "lz4 - Extremely Fast Compression algorithm - Google Project Hosting". Google.com. Retrieved 30 November 2014. 
  4. ^ "Kernel development". LWN.net. Retrieved 30 November 2014. 
  5. ^ "FreeBSD 9.2-RELEASE Release Notes". Freebsc.org. Retrieved 30 November 2014. 
  6. ^ "LZ4 Compression". Wiki.illumos.org. Retrieved 30 November 2014. 
  7. ^ "Illumos #3035 LZ4 compression support in ZFS and GRUB · 9759c60 · zfsonlinux/zfs · GitHub". GitHub. Retrieved 30 November 2014. 
  8. ^ "Features". Open-zfs.org. Retrieved 30 November 2014. 
  9. ^ Merge of LZ4 Squashfs support to Linus Torvalds tree.

External links[edit]