Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Apple Open-Sources its New Compression Algorithm LZFSE

Apple Open-Sources its New Compression Algorithm LZFSE

Leia em Português

This item in japanese

Apple has open-sourced its new lossless compression algorithm, LZFSE, introduced last year with iOS 9 and OS X 10.10. According to Apple, LZFE provides the same compression gain as ZLib level 5 while being 2x–3x faster and with higher energy efficiency.

LZFSE is based on Lempel-Ziv and uses Finite State Entropy coding, based on Jarek Duda’s work on Asymmetric Numeral Systems (ANS) for entropy coding. Shortly, ANS aims to “end the trade-off between speed and rate” and can be used both for precise coding and very fast encoding, with support for data encryption. LZFSE is one of a growing number of compression libraries that use ANS in place of the more traditional Huffman and arithmetic coding.

Admittedly, LZFSE does not aim to be the best or fastest algorithm out there. In fact, Apple states that LZ4 is faster than LZFSE while LZMA provides a higher compression ratio, albeit at the cost of being an order of magnitude slower than other options available in Apple SDKs. LZFSE is Apple’s suggested option when compression and speed are more or less equally important and you want reduce energy consumption.

LZFSE reference implementation is available on GitHub. Building on macOS is as easy as executing:

$ xcodebuild install DSTROOT=/tmp/lzfse.dst

If you want to build LZFSE for a current iOS device, you can execute:

xcodebuild -configuration "Release" -arch armv7 install DSTROOT=/tmp/lzfse.dst

Besides its API documentation, a useful resource to start using LZFSE is a sample project that Apple made available last year to show how to use LZFSE both for block and stream compression.

LZFSE follows on Google’s brotli, which was open sourced last year. In comparison to LZFSE, brotli seems to be tuned for a different use case, such as compressing static Web assets and Android APKs, where compression rates are of prime importance.

Rate this Article