getImageData slow
See original GitHub issueThis 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.
- Is there a work around?
- If not, Would implementing a custom function like
getImageDataMultiple(RectangleArray)
likely solve the issue by reducing the RN -> WebView interaction to a single call? - Would it be accepted back into the source? I’d prefer not to maintain a custom fork if poss.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:9 (4 by maintainers)
Top Results From Across the Web
speed up canvas's getImageData - Stack Overflow
It's still slow but hopefully you won't need to do it often. Below is an example to get an int for each pixel...
Read more >a faster alternative to canvas.getImageData - GitHub
getImageData is really slow. if you want to select sections of image data in a loop, a quicker alternative is to cache the...
Read more >Slow getImageData() and putImageData() performance as ...
It looks like the problem is that getImageData is called before anything was drawn to the canvas. At larger canvas sizes, this means...
Read more >81497 - getImageData really slow in chrome - Monorail
getImageData(0, 0, 25, 25) it's still just as slow. This does not seem to be dependent on the size of the image buffer...
Read more >Why is getImageData so slow in this case? : r/firefox - Reddit
I've found a weird behavior with canvas' getImageData performance in Firefox. If I use it a lot of times, it gets very slow....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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