Skip to content

Extremely slow performance of generateAsync with 3.2.X JSZip versions #617

@TestPolygon

Description

@TestPolygon

generateAsync works ~50 times slower in JSZip 3.2.X than in JSZip 3.1.5!
I use JSZip in a Chromium 76 based browser.

Here is a code to test it:

function addBlobToZipMultipleTimes(blob, times) {
    
    console.log("Input blob.size: ", formatBytes(blob.size));

    const zip = new JSZip();
    
    for(let i = 0; i < times; i++) {
        zip.file("file_" + i, blob);
    }
    
    console.log("generateAsync...");
    console.time("generateAsync");
    zip.generateAsync({type:"blob"})
        .then(function(blob) {
            console.timeEnd("generateAsync");
            console.log("Result zip.size: ", formatBytes(blob.size));
            
            // downloadBlob(blob); // some work with the result zip
        });
}

// https://stackoverflow.com/a/18650828/11468937
function formatBytes(bytes, decimals = 2) {
    if (bytes === 0) return '0 Bytes';

    const k = 1024;
    const dm = decimals < 0 ? 0 : decimals;
    const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

    const i = Math.floor(Math.log(bytes) / Math.log(k));

    return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}

The example

For addBlobToZipMultipleTimes(blob, 1):
JSZIP 3.1.5:

Input blob.size: 2.75 MB
generateAsync...
generateAsync: 22.086181640625ms
Result zip.size: 2.75 MB

JSZIP 3.2.1:

Input blob.size: 2.75 MB
generateAsync...
generateAsync: 926.528076171875ms
Result zip.size: 2.75 MB

JSZIP 3.2.0, 3.2.2 have the same speed.

22 ms vs 926 ms!


Some more examples

JSZIP 3.1.5:

generateAsync: 97.862060546875ms
Result zip.size: 13.76 MB

JSZIP 3.2.1:

generateAsync: 4944.34423828125ms
Result zip.size: 13.76 M

97 ms vs 4944 ms


For 41.29 MB:

JSZIP 3.1.5:

287.92626953125ms

JSZIP 3.2.1:

14723.44287109375ms

287 ms vs 14723 ms


For 137.65 MB:

JSZIP 3.1.5:

858.16796875ms

JSZIP 3.2.1:

49275.451904296875ms

0.8 sec vs 49 sec!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions