edi9999 / jsqrcode

[deprecated] Lazarsoft's jsqrcode as a node module, object oriented, and with tests
Apache License 2.0
278 stars 63 forks source link

Performance issue: QrCode.process is too slow and allocates a lot of heap memory #43

Closed micooz closed 6 years ago

micooz commented 7 years ago

I pass a ImageData(2160 * 3840, Uint8ClampedArray(33177600)) to QrCode.decode(), and it takes about 22s to give me a result. However, I don't think that is a huge image.

There are two main functions in QrCode.process() that affect performance: grayscale() and grayscalegrayScaleToBitmap():

2017-06-27 10-30-51

Can you make some improvements to the gray scale logic and reduce processing time?

edi9999 commented 7 years ago

Good issue.

It would be interesting to see if the speed of the function can be improved.

Your image is quite big imo (8megapixels), if you scale down the resolution to let's say 1 megapixel I suspect it would be 8 times faster.

Lucassifoni commented 7 years ago

I've made some tests inlining some functions like getPixel, and replacing object properties accesses by declaring static variables when possible in grayscale() and grayscaleToBitmap(), with no performance gain.

(Meanwhile, I stumbled upon this article : https://www.nearform.com/blog/node-js-is-getting-a-new-v8-with-turbofan, it seems that the specific bits that I changed just got optimized in latest Chrome versions.)

I've started to convert my fork to only use TypedArrays when possible, but with no performance improvements as of today.

The best results I've had were while delegating the process step to a web worker.

(Also, if you need to scan from a phone camera, I've had great (non-blocking) results with a 60fps requestAnimationFrame loop displaying the video, trying to scan every N frames via a web worker - if it was done processing the last call).

edi9999 commented 6 years ago

I'm closing this as stale, there's not much we can do right now.