-
Notifications
You must be signed in to change notification settings - Fork 512
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
[It took too much time the second time] entry getData #469
Comments
I guess this might be related to your filesystem perfomance. On my end, I cannot reproduce the issue. See the test here https://jsfiddle.net/uLwjpons/, and below. <!doctype html>
<html>
<head>
<title>Test getData in zip.js</title>
<style>
body {
font-family: monospace
}
</style>
</head>
<body>
<script type="module">
import {
BlobReader,
BlobWriter,
ZipReader,
ZipWriter,
} from "https://deno.land/x/zipjs/index.js";
main().catch(console.error);
async function main() {
await log("INIT");
const zipData = await createFile();
await log("RUN");
await runTest(zipData);
await log("END");
}
async function createFile() {
await log("STEP 1/2 (creating data)");
const DATA_64_MB = new Array(64 * 1024 * 1024).fill(Math.floor(Math.random() * 128) * 2);
const ENTRY_DATA = new Blob(new Array(8).fill(DATA_64_MB));
await log("STEP 2/2 (zipping data)");
const zipFileWriter = new BlobWriter();
const entryDataReader = new BlobReader(ENTRY_DATA);
const zipWriter = new ZipWriter(zipFileWriter);
await zipWriter.add("test.bin", entryDataReader);
return zipWriter.close();
}
async function runTest(zipData) {
const zipFileReader = new BlobReader(zipData);
const zipReader = new ZipReader(zipFileReader);
const firstEntry = (await zipReader.getEntries()).shift();
const iterations = new Array(9).fill().map((_, index) => index 1);
for (const iteration of iterations) {
const startTime = performance.now();
await firstEntry.getData(new BlobWriter());
await log(`TEST ${iteration}/9 => ${performance.now() - startTime} ms`);
}
}
async function log(value) {
document.body.innerHTML = `${value}<br>`;
await pause();
}
function pause() {
return new Promise(resolve => setTimeout(resolve, 500));
}
</script>
</body>
</html> Here are the logs when I run this test in Chrome. Performance is constant.
|
@gildas-lormeau
|
If you pass a |
@gildas-lormeau |
I know that. I suspect the problem is coming from your filesystem, when reading the compressed data in the ZIP file. That's why I asked you to do a test and pass a |
@gildas-lormeau
I just tried again and noticed that the time has reduced a bit, but there is still an issue because the second time takes longer, and I don't know the reason: First attempt: 35s Additionally, when running, occasionally the following error appears: |
Thank you, maybe you are leaking memory and using the swap too much? Have you looked at what's happening at this level? |
Can you reproduce the issue with this test https://run.plnkr.co/preview/clq8gh5r400033b6ti2ixuutk/ in Chrome? If the link is broken, go to https://plnkr.co/edit/C8QoHl0kBD3dQMxV?preview and open the test page in a new tab by clicking the corresponding button in the upper right of the preview page. It's using the filesystem API in order to create the ZIP file on the disk. On my end, I'm still getting constant results.
<!doctype html>
<html>
<head>
<title>Perf test of Entry#getData in zip.js</title>
<style>
body {
font-family: monospace;
}
</style>
</head>
<body>
<button id=runTestButton>Run</button>
<script type=module>
import {
BlobReader,
BlobWriter,
ZipReader,
ZipWriter,
} from "https://deno.land/x/zipjs/index.js";
const ZIP_EXTENSIONS_ACCEPT = {
"application/zip": [".zip"],
};
const ONE_MB = 1024 * 1024;
runTestButton.addEventListener("click", async () => {
let fileHandle;
try {
const suggestedName = [...new Array(16)].map(() => Math.floor(Math.random() * 16).toString(16)).join("") ".zip";
fileHandle = await showSaveFilePicker({
suggestedName,
mode: "readwrite",
startIn: "downloads"
});
createZIPButton.remove();
await log("INIT");
const writable = await fileHandle.createWritable();
const zipWriter = new ZipWriter(writable);
const addFilePromises = [];
const writers = [];
for (let i = 0; i < 4; i ) {
const transformStream = new TransformStream();
addFilePromises.push(zipWriter.add(`test${i}.bin`, transformStream.readable));
writers.push(transformStream.writable.getWriter());
}
await log("STEP 1/1 (creating and zipping data)");
await Promise.all([
...writers.map(writer => fillData(writer)),
...addFilePromises
]);
await zipWriter.close();
const file = await fileHandle.getFile();
const zipReader = new ZipReader(new BlobReader(file));
const firstEntry = (await zipReader.getEntries()).shift();
const iterations = new Array(9).fill().map((_, index) => index 1);
await log("RUN");
for (const iteration of iterations) {
const startTime = performance.now();
await firstEntry.getData(new BlobWriter());
await log(`TEST ${iteration}/9 => ${performance.now() - startTime} ms`);
}
await log("END");
} finally {
if (fileHandle) {
await fileHandle.remove();
}
}
});
async function fillData(writer, currentSize = 0, maxSize = Math.floor((Math.random() * 256) 512) * ONE_MB) {
const chunkSize = ONE_MB;
const chunk = new Uint8Array(chunkSize);
for (let i = 0; i < chunkSize; i ) {
chunk[i] = Math.floor(Math.random() * 128) * 2;
}
await writer.write(chunk);
currentSize = chunkSize;
if (currentSize < maxSize) {
await fillData(writer, currentSize, maxSize);
} else {
await writer.close();
}
}
async function log(value) {
document.body.innerHTML = `${value}<br>`;
await pause();
}
function pause() {
return new Promise(resolve => setTimeout(resolve, 500));
}
</script>
</body>
</html> |
Thank you, Gildas Lormeau. I used a different approach by using the 'encrypt' variable, and it resolved the issue. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I am encountering an issue when using the @zip.js/zip.js library, version ^2.7.32. I have checked and identified an error in the getData code:
The first time I select a zip file (containing other files inside), getData takes about 44 seconds. However, from the second time onwards, the process takes over 10 minutes. I have rerun it multiple times, and the result is consistently the same.
The environments used are:
Edge Version 120.0.2210.61 (Official build) (64-bit)
Chrome Version 119.0.6045.159 (Official Build) (64-bit)
Can anyone help me? Thanks!
The text was updated successfully, but these errors were encountered: