Performance Optimization of Java Compression in MJDK Using ISA‑L Based mzlib

The article explains how MJDK, Meituan's OpenJDK‑based distribution, integrates the Intel ISA‑L‑optimized mzlib library into java.util.zip, preserving API and format compatibility while delivering a five‑to‑ten‑fold increase in compression and decompression throughput, backed by benchmark results on the Silesia corpus.

Meituan Technology Team
Meituan Technology Team
Meituan Technology Team
Performance Optimization of Java Compression in MJDK Using ISA‑L Based mzlib

1. Introduction

MJDK is Meituan's JDK distribution built on OpenJDK. The article describes how MJDK integrates the Intel ISA‑L‑optimized mzlib library to replace the default zlib implementation used by java.util.zip, achieving a 5‑10× speedup in compression and decompression while keeping API and format compatibility.

2. Data Compression Techniques

Data compression reduces storage and transmission costs and is widely used in networking, file transfer, databases, and operating systems. The article reviews the history of lossless compression, from Shannon's information theory to modern algorithms such as Deflate, gzip, and zlib, and lists recent open‑source compressors like LZFSE, Brotli, and Zstandard.

3. Compression APIs in Java

Java provides two ways to perform compression: the native java.util.zip.* classes (which internally call the zlib library via JNI) and third‑party JARs that wrap other native libraries. The article shows example code for zip and gzip compression using the native API and a Snappy example using a third‑party library.

public class ZipUtil {
    // compress
    public void compress(File file, File zipFile) {
        byte[] buffer = new byte[1024];
        try {
            InputStream input = new FileInputStream(file);
            ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
            zipOut.putNextEntry(new ZipEntry(file.getName()));
            int length = 0;
            while ((length = input.read(buffer)) != -1) {
                zipOut.write(buffer, 0, length);
            }
            input.close();
            zipOut.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // decompress
    public void uncompress(File file, File outFile) {
        byte[] buffer = new byte[1024];
        try {
            ZipInputStream input = new ZipInputStream(new FileInputStream(file));
            OutputStream output = new FileOutputStream(outFile);
            if (!outFile.getParentFile().exists()) {
                outFile.getParentFile().mkdir();
            }
            if (!outFile.exists()) {
                outFile.createNewFile();
            }
            int length = 0;
            while ((length = input.read(buffer)) != -1) {
                output.write(buffer, 0, length);
            }
            input.close();
            output.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
public class GZipUtil {
    public void compress(File file, File outFile) {
        byte[] buffer = new byte[1024];
        try {
            InputStream input = new FileInputStream(file);
            GZIPOutputStream gzip = new GZIPOutputStream(new FileOutputStream(outFile));
            int length = 0;
            while ((length = input.read(buffer)) != -1) {
                gzip.write(buffer, 0, length);
            }
            input.close();
            gzip.finish();
            gzip.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void uncompress(File file, File outFile) {
        try {
            FileOutputStream out = new FileOutputStream(outFile);
            GZIPInputStream ungzip = new GZIPInputStream(new FileInputStream(file));
            byte[] buffer = new byte[1024];
            int n;
            while ((n = ungzip.read(buffer)) > 0) {
                out.write(buffer, 0, n);
            }
            ungzip.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

4. MJDK Optimization Strategy

Since java.util.zip ultimately relies on zlib, improving JDK compression performance reduces to optimizing the underlying zlib library. MJDK adopts Intel's open‑source ISA‑L (which uses SSE/AVX instructions for parallel processing) to replace the standard zlib implementation, creating the mzlib library.

4.1 Modification Process

The mzlib integration preserves the original Java API signatures, ensuring existing code continues to work. Compatibility tests confirm that Zip and Gzip interfaces function correctly with the new library.

4.2 Performance Evaluation

Benchmarks were run on the Silesia corpus using OpenJDK 7u76, 8u45, and 8u312 as baselines. Results show that MJDK8_mzlib reduces compression time by 5‑10× compared with OpenJDK 8, while the compression ratio changes by only about +3%.

Compatibility: All Zip/Gzip operations succeed with the modified classes.

Speed: Compression time drops dramatically (5‑10× faster).

Ratio: Compression ratio remains essentially unchanged (+/- 3%).

Production usage in Meituan's collaborative editing service (compressing >6 MB records) has run stably for over three years, confirming the real‑world benefits.

5. Conclusion

By integrating the ISA‑L‑based mzlib into the JDK, MJDK delivers a substantial throughput improvement without breaking API compatibility, offering a practical solution for Java services that rely heavily on data compression.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaPerformanceJNIcompressionzlibISA‑LMJDK
Meituan Technology Team
Written by

Meituan Technology Team

Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.