Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async unzip maxing out CPU and memory for some files #191

Closed
tmatson98 opened this issue Nov 20, 2023 · 3 comments
Closed

Async unzip maxing out CPU and memory for some files #191

tmatson98 opened this issue Nov 20, 2023 · 3 comments

Comments

@tmatson98
Copy link

How to reproduce

The issue can be reproduced with the following code:

const sync = false;
const contents = {};
for (let i = 0; i < 80; i += 1) {
  contents[`file-${i}`] = new Uint8Array(Array.from({ length: 1024 * 1024 }, () => Math.floor(Math.random() * 256)));
}
const zipped = zipSync(contents);
console.log('Unzipping');
const start = performance.now();
if (sync) {
  unzipSync(zipped);
  console.log(`${performance.now() - start} ms`);
} else {
  unzip(zipped, null, () => {
    console.log(`${performance.now() - start} ms`);
  });
}

The problem
Trying to decompress a moderately large ZIP file (~80 MB) containing files of 200 kB to 1 MB using the async unzip function maxes out my system memory and CPU. Using unzipSync instead works perfectly and takes less an 100ms in the above code, while unzip takes a full minute. Increasing the ZIP size to 150 MB can cause unzip to fail with this error:

Uncaught DOMException: The object could not be cloned.
    cbify browser.js:910
    inflate browser.js:1174
    _loop_3 browser.js:2547
    unzip browser.js:2556

Decompressing a ZIP with 8 10MB files works okay so it seems to be mainly caused by the number of files, but the unzipSync function is still much faster decompressing it. Using a performance profiler the issue seems to be with the postMessage WebWorker function.

Test machine has an i7 6700, 16GB RAM

@101arrowz
Copy link
Owner

I'll try to address this in the next update. unzip should be strictly faster than unzipSync for sufficiently large ZIPs.

@101arrowz
Copy link
Owner

101arrowz commented Feb 6, 2024

Reproduced locally. I have a potential fix for the slow performance but the crashing on ZIPs with hundreds of medium-size files might be more related to #58 than anything.

@101arrowz
Copy link
Owner

Fixed in v0.8.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants