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

The version 3.0.0 is not async in chrome #280

Closed
CVex2150J opened this issue Apr 20, 2016 · 5 comments
Closed

The version 3.0.0 is not async in chrome #280

CVex2150J opened this issue Apr 20, 2016 · 5 comments

Comments

@CVex2150J
Copy link

CVex2150J commented Apr 20, 2016

I was using jszip 2.6.0 for at least 1 years and it work great with a minus problem("stopping" javascript execution for a while) but it was "ok". Now with the chrome upgrade 50.0.2661.75 m I get "aw snap" page most of the time (I zip a large string therefore stalling the javascript for more than 20 sec of work).
I'm really happy to see v3.0.0 with all thoses async methods. But during my tests for the last 2 days to solve my "aw snap" problem I found that on chrome 50 and using the latest build and async functions... my javascript block at generateAsync()

I did a test on NodeJS and it seems to work ok (not 100% sure)

There is a screenShot of chrome devTool. I tried to generate a zip with 22 files in it (~21MB of data). The flush function block all javascript execution for 4.73s.

I will use multiple zips generation as a work around for the moment.

jszipnotasync

@dduponchel
Copy link
Collaborator

Could you give us a code sample ? Several things can affect the speed: the type of file contents, parameters given to file(name, data), generateAsync(), etc. But not to that point.
In your case, I can see several _tickAndRepeat that should be separated by at least some milliseconds.
I tried to reproduce the issue (with Chromium 50.0.2661.75 and 20 files of 1 MB) but I get ~100ms chunks of executions separated by ~10ms. Here is the code I used.

@CVex2150J
Copy link
Author

I tried your script with multiple 1MB files and it`s worked. I tested mine with File or ArrayBuffer, and it worked too. However, when I used a bigger file 10 - 20MB for example, I got the same behaviour as my first post.
Is there a kind of task splitting when one file is to heavy to be done in one go?
I will do more testing during the week-end.

@dduponchel
Copy link
Collaborator

It looks like the issue comes from asap which isn't the right tool here. The documentation says

ASAP strives to schedule events to occur before yielding for IO, reflow, or redrawing.
[...]
If this is a problem, you may be able to use ASAP’s cousin setImmediate to break long processes into shorter intervals and periodically allow the browser to breathe.

YuzuJS/setImmediate updates the global object, I'll check zloirock/core-js.

dduponchel added a commit to dduponchel/jszip that referenced this issue Apr 26, 2016
As says the documentation of [asap](https://github.com/kriskowal/asap),

> ASAP strives to schedule events to occur before yielding for IO,
> reflow, or redrawing.

The goal of async methods in JSZip is to not freeze the browser, a macro task
is a better choice here. See
https://github.com/YuzuJS/setImmediate#macrotasks-and-microtasks for a
description of micro/macro tasks.

Fix Stuk#280.
@CVex2150J
Copy link
Author

I just tried the pull request and nothing change in the chrome profile. There is always a big long flush() call if the file is large enough. I tested it in nodejs ( simple fs readFile -> zipping uInt buffer and trying to write a stdout every sec) and it freezed for couple of second every time. I'll post script and zip sample to be able to test the code from now on.

@dduponchel
Copy link
Collaborator

@CVex2150J I updated the plunker here to use https://rawgit.com/dduponchel/jszip/fix_280_dist/dist/jszip.js instead of the v3.0.0 file and I get the expected result (I get the bug with the old plunker, not with the new one):
issue280

Same with nodejs. With the following script

var JSZip = require("./jszip_pr288");
var fs = require("fs");
var tickCount = 0;
setInterval(function () {
    console.log("tick", tickCount);
    tickCount++;
}, 200);

var zip = new JSZip();
for (var i = 1; i <= 20; i++) {
    // 20 files, generated with
    // for i in `seq 1 20`; do
    //   dd if=/dev/urandom of=$i.data bs=1M count=$i
    // done
    zip.file("" + i, fs.readFileSync(i + ".data"));
}

console.log("start");
zip.generateAsync({type:"arraybuffer", compression:"DEFLATE"})
.then(buffer => console.log(buffer));

I get regular tick in the console.

How do you reproduce your issue with the updated files from the pull request ?

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