-
Notifications
You must be signed in to change notification settings - Fork 1.6k
How to prevent JavaScript freezing in readStream #118
Comments
@stefan-feltmann , thank you for point out this problem. Could you let me know which |
@stefan-feltmann , after some investigation, I think the problem is result from high frequency event dispatching, however, thank to this issue, I've also found a bug in IOS I've changed the code and try to reduce the overhead when handling RCT bridge event, though the problem may still exists, I'm able to read a 22MB file in about 3 seconds (on iPhone 6) by increase the buffer size to 102400(25x of default value). Please try the latest version |
I'm using utf8. Currently it's only happening on Android. iOS is having issues which may or may not be related to I will try |
I tried both I'll get back to you with iOS information as soon as I can. |
@stefan-feltmann , great thanks for the assistance 👍 I've published On IOS when the buffer size is large (about ~1000k) the app crashes due to IOS thread stack size limit (1MB). In this version the stream buffer is moved to heap instead of in heap, so that it's managed to use a large buffer and it's working seemly on iPhone. As for Android, I've found a possible solution, we were using AsyncTask instead of thread pool when read data using filestream (most of fs and network API are using thread pool since 0.8.0, perhaps I've just missed |
Introduce new argument which can limit readStream event frequency
FYI, the latest release fs
// read file with 400kb buffer and with an interval 100ms
.readStream(PATH_TO_FILE, 'utf8', 409600, 100)
.then((stream) => {
// open file stream
stream.open()
stream.onData((chunk) => { /* do something with the chunk */ })
stream.onEnd(() => { /* do something */ })
}) Please try if this solve the problem 😄 |
I tried One other thing that you might want to consider. I came across this article about breaking up heavy processing in React Native. I'm not sure if it's possible with this library, but if it's possible to load each chunk immediately after each UI repaint, maybe that will elegantly solve the freezing problem. But like I said, the new |
@tsemerad , great to hear that 😄 From my understanding, the root cause of this issue is that native module dispatch event in a very high frequency, as such there is a large overhead converting native object to JS context which makes the JS VM very busy. Therefore I tried to reduce the frequency by adding extra option to the API. However I've never think about |
Thanks a lot for looking into this. |
Fixed truncating of progress report values.
I'm having an issue streaming in a file with
readStream
. WhileonData
is being called the JS thread freezes for about nine seconds opening a 16.6 MB file. I've tried increasing the buffer to 20000000 from default and that did speed it up from its old time of about forty five seconds, but further increase didn't change anything and if the buffer is set too high, the app crashes. Is there something straightforward I'm missing, or is this expected behavior?The text was updated successfully, but these errors were encountered: