Brotli is an open-source compression algorithm that was released publicly by Google back in 2015. Unlike gzip, it was not initially released for use as a standalone algorithm, but rather as an offline compression solution for the WOFF2 font format. Within a few months, it was adopted by various browsers including Firefox, Opera, and Chrome. Back in December 2016, even Microsoft Edge started supporting Brotli as it allows webpages to load faster, and consumes less data and power while browsing the web.
Now, Microsoft has conducted some tests to see how Brotli compares to the competition, along with announcing an alpha preview for the .NET Framework and .NET Core applications.
Microsoft explains that three factors determine the quality of every compression algorithm. These are:
- Compression ratio
- Compression time
- Decompression time
To test the first factor, the company compared it with two existing compression algorithms, gzip and Deflate. Two variations of this test were conducted: "Fastest", which lets the algorithms compress the data as quickly as possible; and "Optimal", which lets the algorithm take as much time as it wants.
All three compression algorithms were provided with various data sets. For CSS, Brotli performed about the same as the competition on Fastest and was better on Optimal. In HTML and JavaScript, even at "middle" quality level, the algorithm was better than both gzip and Deflate at Optimal configurations. With regards to the Canterbury Corpus - which is a popular set of files used to test compression algorithms - Brotli turned out to be a massive improvement over the competition for larger files, and was slightly better, or on par with, relatively smaller files. You can check out the results for the Canterbury Corpus below (higher is better):
The second factor that was benchmarked was compression time. Although at Optimal configuration, Brotli turned out to be considerably slower than both gzip and Deflate, it was much faster at Fastest. Further testing concluded that Brotli"s compression time depends upon the quality level. From a quality scale of 1-11, the algorithm excels below 10, as can be seen in the graph below (lower is better):
The last determining factor was decompression time, and results showed that Brotli and gzip were almost equal, but vastly superior to Deflate. You can check out the data below (lower is better):
As gzip had turned out to be better than Deflate in almost all benchmark tests, a "bonus metric" was then used to compare it with Brotli. Silicon Valley fans will be delighted to know that the Weissman Score, a test that was introduced and popularized by the TV show, was utilized. The formula takes into account both the compression ratio as well as the time taken. With gzip used as the baseline, a score of less than 1 would indicate that gzip was better, while a score of greater than 1 would give the crown to Brotli. As can be seen in the graph representation below, the ultimate winner was Google"s compression algorithm, by far:
As a result, Microsoft has announced that .NET support for Brotli is now available as an alpha preview. It can be used with both the .NET Framework as well as .NET Core applications. The company has detailed the process for those who are eager to test out the algorithm on its blog post. You can download the source code from CoreFxLab repository, and can file any relevant issues there as well.