← Blog

Shrinking iOS and macOS with Crush-LZ

Ever wonder why iOS and macOS are so large? A big portion of that is poor data compression. Testing with Crush-LZ and apfscompress shows that Apple could shrink iOS & macOS system installs by up to 12%, while increasing decompression speed by up to 38%.

How Apple Compresses

Apple already uses compression to reduce the size of iOS and macOS installations. The supported algorithms are stored in AppleFSCompressionTypeZlib.kext, which ships a subset of the algorithms available for apps in Compression.framework.

Of the 5 algorithms APFS supports, Apple never uses LZFSE, which they introduced in 2015 as a faster alternative to zlib. Today, macOS uses LZVN and LZBITMAP, and iOS uses zlib and LZBITMAP:

iOS 20.6 GiB of files → 13.9 GiB stored 6.7 GiB saved macOS 27.4 GiB of files → 14.3 GiB stored 13.1 GiB saved zlib LZVN LZBITMAP Uncompressed Space saved
Figure 1. How Apple stores the system installs. Colored sections distinguish formats and uncompressed files; the light section is space already saved. iOS 27.2 build 24B119; macOS 27.2 build 26B123.

There are two primary problems:

  • Apple’s choice of algorithms is suboptimal
  • Compression.framework prioritizes speed over ratio

Each of these gaps costs storage space and performance.

Picking the Right Algorithm

For building an operating system, compression time is a one-time cost - a few minutes of build time per release. Ratio and decompression speed are what matter, as they are paid on every software update and every system startup for billions of users. Below is a graph of the algorithms on a ratio/decompression speed chart:

30% 35% 40% 45% 1 2 4 8 Decompression Speed vs Ratio (Apple Compressors) Compressed size / original · smaller ← Decompression (GB/s) · faster ↑ zlib 28.5% · 1.4 GB/s LZFSE 29.4% · 2.6 GB/s LZVN 33.7% · 2.2 GB/s LZBITMAP 33.7% · 6.5 GB/s LZ4 42.2% · 7.6 GB/s
Figure 2. All five formats on a 500 MiB corpus. Apple encoders are used except for reference zlib at level 9.

Remember how macOS uses LZVN? LZFSE is better in both decompression speed and ratio, so swapping LZVN for LZFSE is an obvious win for macOS.

Battle Royale

It turns out we can do better than just swapping the primary algorithms. APFS allows us to pick the best format on a per-file basis - this slightly boosts both ratio and speed, as LZBITMAP wins a small portion of files outright.

Using Apple’s own encoders, that makes the compressed iOS files about 3% smaller, with 16% faster decompression, and the compressed macOS files about 8% smaller, with 23% faster decompression:

Shipped formats · Apple encoders 4.46 GiB · 7.2s decompression Optimal formats · Apple encoders 4.32 GiB · 6.2s decompression zlib LZVN LZFSE LZBITMAP
Figure 3 · iOS 27.2. Choosing better formats with Apple's own encoders. Most iOS bytes stay zlib, because zlib usually compresses them more densely than Apple's LZFSE. Bars cover the compressed files in this install; dashed sections show extra savings relative to the shipped files.
Shipped formats · Apple encoders 9.10 GiB · 9.6s decompression Optimal formats · Apple encoders 8.37 GiB · 7.8s decompression zlib LZVN LZFSE LZBITMAP
Figure 3 · macOS 27.2. Choosing better formats with Apple's own encoders. LZVN nearly disappears as LZFSE and LZBITMAP take its place. Bars cover the compressed files in this install; dashed sections show extra savings relative to the shipped files.

This is the limit with Apple’s compressors - but we can do better. For a one-time operating system build, there’s no reason to use a compressor built for high-speed compression rather than optimized data packing.

Optimizing the Compressor

Crush-LZ spends additional CPU time during compression to represent the same data in less space. This results in substantial ratio gains for LZFSE and LZBITMAP, with small gains for zlib. LZVN and LZ4 are not competitive even when optimized.

In this chart, no file is ever switched to a slower algorithm, and both configurations decompress faster than Apple’s current shipping config. Crush-LZ’s maximum ratio configuration for LZFSE is slightly slower to decompress than Apple’s LZFSE, but speed can be restored by giving back some of the ratio gains using the encoder’s tuple_tax parameter.

Optimal formats · Apple encoders 4.32 GiB · 6.2s decompression Optimal formats + Crush-LZ 3.98 GiB · 4.7s decompression (vs 7.2s shipped) zlib LZVN LZFSE LZBITMAP
Figure 4 · iOS 27.2. The additional gain from Crush-LZ, after format selection. Bar lengths share the scale of Figure 3; dashed sections show total savings relative to the shipped files.
Optimal formats · Apple encoders 8.37 GiB · 7.8s decompression Optimal formats + Crush-LZ 7.56 GiB · 8.1s decompression (vs 9.6s shipped) zlib LZVN LZFSE LZBITMAP
Figure 4 · macOS 27.2. The additional gain from Crush-LZ, after format selection. Bar lengths share the scale of Figure 3; dashed sections show total savings relative to the shipped files.

LZFSE gains substantially from additional compute, replacing most zlib-compressed files on iOS. LZVN is not competitive on either platform once LZBITMAP is optimized.

Mapping the Frontier

The Pareto frontier includes a variety of other space/performance tradeoffs. Notably, Apple is not remotely close to this frontier:

4 4.25 4.5 4.75 0 2 4 6 8 Stored size (GiB) · smaller ← Decompression (seconds) · faster ↓ Smaller and faster than shipped Apple ships 4.46 GiB · 7.2s Apple · balanced 4.32 GiB · 6.2s Crush-LZ · balanced 3.98 GiB · 4.7s Apple · LZBITMAP 4.71 GiB · 2.0s Crush-LZ · LZBITMAP 4.32 GiB · 2.0s Apple · smallest 4.24 GiB · 6.8s Crush-LZ · smallest 3.90 GiB · 5.2s
Figure 5 · iOS 27.2. The same compressed system files, with different priorities.
7.5 8 8.5 9 0 5 10 15 Stored size (GiB) · smaller ← Decompression (seconds) · faster ↓ Smaller and faster than shipped Apple ships 9.10 GiB · 9.6s Apple · balanced 8.37 GiB · 7.8s Crush-LZ · balanced 7.56 GiB · 8.1s Apple · LZBITMAP 8.78 GiB · 4.1s Crush-LZ · LZBITMAP 8.04 GiB · 4.1s Apple · smallest 8.14 GiB · 13.6s Crush-LZ · smallest 7.40 GiB · 10.3s
Figure 5 · macOS 27.2. The same compressed system files, with different priorities.

Crush-LZ offers material gains over Apple’s current configurations:

  • iOS takes 600 MB less space, and decompresses 38% faster (smallest)
  • macOS takes 1.825 GB less space, and decompresses 18% faster (balanced)

After adding back in uncompressed files, this cuts about 4% off the current size of an iOS install, and 12% off the size of a macOS install.

Potential Surprises

Apple may be planning to replace LZVN / LZFSE entirely with LZMesh, a new compression algorithm that arrived in Compression.framework recently, but has not yet reached APFS. LZMesh is a better algorithm overall, so this would be an excellent outcome.

Crush-LZ includes a compressor for LZMesh, offering ratio gains of nearly 2% over Apple’s LZMesh implementation. It is not as heavily optimized as the LZFSE & LZBITMAP compressors, but I plan to optimize it further if LZMesh reaches APFS.

Final Notes

I have a tendency to run out of storage space, so I’m really hoping to see compression improvements for macOS and iOS in the future. Alas, except for custom-kernel Macs and VMs, denser system images are on Apple’s timeline.

However Crush-LZ and apfscompress can do far more than just compress system files. Shrink Wizard uses apfscompress to save disk space by compressing applications on your device, and apfscompress can shrink DMGs so you can deliver smaller precompressed app installs to users.

May your files be ever-shrinking, and your storage remain plentiful.