gruhn / vue-qrcode-reader

A set of Vue.js components for detecting and decoding QR codes.
https://gruhn.github.io/vue-qrcode-reader
MIT License
2.12k stars 334 forks source link

use paused introduce around 1s to 2s of freeze #420

Closed flapili closed 6 months ago

flapili commented 9 months ago

Describe the bug I need to scan multiples times the same QRcode with low latency (< 250ms) the usecase is for point of sales with multiples times the same barcode

To Reproduce https://stackblitz.com/edit/vue3-script-setup-with-vite-h2dnn7?file=src%2FApp.vue

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

I tryed to take a look at source code to make a PR but I have no idea where the issue is

gruhn commented 9 months ago

Thanks for the demo. Note that scanning is slower the more barcode formats you select. If I select only qr_code or only ean_13 in your demo, I get significantly less delay. You can log the detected codes in paintOutline to see the true scanning frequency:

function paintOutline(detectedCodes, ctx) {
    console.debug(detectedCodes)

That logs detected codes at maximum rate no matter what you do with the paused prop. But note that it's not recommended to update state in this function, since it's called so frequently at might cause memory leaks.

flapili commented 9 months ago

That logs detected codes at maximum rate no matter what you do with the paused prop. But note that it's not recommended to update state in this function, since it's called so frequently at might cause memory leaks.

thanks for the quick response, I didn't think about paintOutline 😅

I suppose with a throttle the risk of memory leaks should be attenuated no ?

gruhn commented 9 months ago

I suppose with a throttle the risk of memory leaks should be attenuated no ?

You can try. At your own risk though 😜

On my end, reducing the number of formats seemed sufficient to improve latency. Can you confirm?

github-actions[bot] commented 7 months ago

This issue has been marked as stale. If there is no further activity it will be closed.