question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getImageData slow

See original GitHub issue

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.

  1. Is there a work around?
  2. If not, Would implementing a custom function like getImageDataMultiple(RectangleArray) likely solve the issue by reducing the RN -> WebView interaction to a single call?
  3. Would it be accepted back into the source? I’d prefer not to maintain a custom fork if poss.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
runrevbencommented, Nov 27, 2020

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.

1reaction
runrevbencommented, Nov 23, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found