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.

NotFoundException slowing this down by lots...

See original GitHub issue

Hello!

I’ve worked pretty hard on speeding up my barcode scanner as much as I could. You can see a snippet of my code to crop the video feed, this has divided by 3 the processing time here!

https://github.com/zxing-js/library/issues/305

Another big point seems to be the NotFoundException which is a ts-custom-error. Using chrome inspection, I have took a sample of 3128 ms while scanning. Of those 3128 ms, 2241ms are using for creating those exceptions.

1026ms by the NotFoundException constructor 1185ms by the fixStack method called by that constructor.

I am not sure if native Errors would fix the issue, make it worse or better. But I am sure there is something better to do in this field. One would argue that errors shouldn’t be flying at high velocity like they are in this library. They are meant to be used when something went wrong, while here we simply expect it to happen quite often and does not mean something went wrong.

My guess is that using native Errors would help as Error.captureStackTrace would not be used every time (I doubt this is very useful for this kind of exception).

Another approach (that feels a bit hacky) would be to keep sending the same instance of NotFoundException. The idea is that the call stack would be the same anyways since it is called from a setTimeout, the stack is new. The only one that has a better stack is the first one thrown as it starts from the setup promise fulfill. Throwing the same exception again and again poses no real risk, we could freeze it just in case. This method would benefit from saving the time to create the new Error object which is very time consuming when done that many times.

My third suggestion would be to get rid of the throwing mechanic to prefer returning a null/false/empty value when a code is not found.

In case you wonder: I was on Chrome 83, with a 640x480 webcam displaying on a 375x812 sized debug screen. And this setup code:

      const config = new Map();
      config.set(ZXing.DecodeHintType.TRY_HARDER, true);
      config.set(ZXing.DecodeHintType.POSSIBLE_FORMATS, [/* ZXing.BarcodeFormat.EAN_8, */ZXing.BarcodeFormat.EAN_13]);

      this.codeReader = new ZXing.BrowserMultiFormatReader(config);
      this.codeReader.timeBetweenDecodingAttempts = 10;

Issue Analytics

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

github_iconTop GitHub Comments

9reactions
kenlyoncommented, Dec 16, 2020

I think that the amount of exception logging here is way over the top. It might be useful in some kind of verbose troubleshooting mode, but for normal production use, I don’t want my console being flooded with “exceptions” just because the program hasn’t yet detected a barcode in the camera image.

Could we consider changing this to some kind of optional setting? I would suggest that all five places where you use console.log() within a catch block should be conditional.

If you’re concerned about backwards compatibility, you could make the default behaviour the current and have to opt in to hide the logging. (Although my preference would be the opposite. I can’t imagine those errors are useful.)

0reactions
cmawhortercommented, Nov 13, 2021

the most important part of OPs post was kinda glossed over:

ts-custom-error […] My guess is that using native Errors would help as Error.captureStackTrace would not be used every time (I doubt this is very useful for this kind of exception).

FWICT, it’d be pretty simple to remove capturing stack from the ts-custom-error file and just copy that file here sans fixStack call. nothing fancy is happening there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Check if WMI ManagementObject query is Nothing instead of ...
This is just sloppy programming and is slowing my program down significantly! My questions is: What do I check in order to use...
Read more >
Some Hints and Tips when using Oracle Functions
Whilst I was writing this piece of code I learnt a lot about Functions ... the garbage collector is running around and slowing...
Read more >
Tag: Best Practices - Billy Korando
Parent POMs can also become a huge burden slowing down build times, bloating the size of artifacts, and causing other problems in projects...
Read more >
Fix list for Rational Functional Tester - IBM
... the secured pages such as payment pages of the mobile application were slow. ... swipe up and swipe down navigation actions failed...
Read more >
R.attr | Android Developers
Defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu. int, configChanges.
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