-
Notifications
You must be signed in to change notification settings - Fork 171
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
getImageData slow #198
Comments
Hey, thank you for taking the time for explaining your issue. I’d say getImageDataMultiple is a little too specific but I’d be glad to add some batching functionally. I think it can be done if the component will wait for the next tick before sending the request to the WebView then multiple requests can be sent together and return together (assuming they are called with Promise.all or without await). Even without changes to the code if you are not using Promise.all right now it should really help with performance of multiple calls to the webview |
OK thanks. We are currently using a mixture of promise.all and await.. I'll look at refactoring to remove the await. Batching sounds like a great idea though. If you think that's something that can realistically be added we'd be happy to help with development, unless it's straightforward for you? I'm expecting our app will increase its dependance on getImageData so being able to batch would be a bit benefit. Cheers, Ben |
I removed all my awaits and put the calls the getImageData in to a Promise.all call. It didn't make a great deal of difference to the performance. I'm wondering if I'm doing it right?
All the data is returned as expected but there is a considerable wait between data being returned during the map |
I'm not sure how this get code works as you don't return the promise in the map function. But assuming you are, yes this is the correct way to do this (using async/await in the map function is fine). As I wrote in the previous comment. It is realistic to add on the RPC level between React Native and the WebView a batching mechanism that waits for the next tick and sends multiple calls to the WebView at once. |
Hi @iddan, we changed our code again as per your comments to return the promises and then resolved all our data once then promise.all returned. Unfortunately the performance improvement was minimal. I'd be interested in your thoughts re implementing batching in your code. I think that would help us and others as it appears this library is the best on out there for Canvas and ReactNative. I'd be happy to show you what our app is doing and even get a developer to try and help implement the changes if that's useful. |
Check the code here: https://github.com/iddan/react-native-canvas/blob/master/src/Bus.js this is the object managing communication with the webview on the React Native side. |
Hi @idan, I have found that getImageData is taking too long , Could you please help us with the batch approach ? Thanks |
Hey @iddan , Can you please help me in finding out the batch approach? Thanks in advance for help!! |
Can someone post a MRE because nothing here proves that it's an underlying issue to the messager here. getImageData is very slow by default, and calling it multiple times in a loop is expected to be very slow, in javascript. |
Closing this issue due to inactivity |
This is a super component and we've been using extensively in a project. Happy to contribute should someone be able to point me in the right direction:
I'm implementing a component that has to use getImageData() multiple times in a loop. Of the 10 or so calls in each loop, some take up to 500ms to resolve, others just 5ms. I'm guessing that the performance issue relates to the messaging between RN and the WebView, rather than the getImageData() call.
getImageDataMultiple(RectangleArray)
likely solve the issue by reducing the RN -> WebView interaction to a single call?The text was updated successfully, but these errors were encountered: