When I try to execute this sketch that is based on a face recognition algorithm it really lags on raspberry, whereas when run on different devices (macbook pro and notebook), it runs smoothly. You can test it using chrome or chromium as a browser.

I am not sure what is the best way to optimise this code so It can run faster. I use it with a local node server directly on the pi. I ran a profiler on chrome with it, and clmtrck.js script seems to be the main bottleneck. I would like to run it around 25/30fps.

I am wondering if any of you have experience optimising code for raspberry and if this kind of hardware acceleration might be an option. Or if there is any cheap method to "boost" a raspberry.

Any pointer is welcome. Thanks!

  • Hi @Guillaume_slize, and welcome to Stack Exchange. Could you provide more details about how the algorithm is lagging? Also, what are you trying to achieve with this? If we know what your timing constraints are, and if you can (in general) be more specific, it might be easier to give you a suggestion.
    – David
    Commented Mar 21, 2019 at 14:00
  • Hi @David and thanks for your comment. I added some details above. Commented Mar 21, 2019 at 14:57
  • great. So, if I understand correctly, you want to process pictures at 25 (up to 30) fps. But what's the resolution of these pictures? And also, do you want to process them non-stop, or is there a finite number of pictures you need to process within a time-frame?
    – David
    Commented Mar 21, 2019 at 15:08
  • So the resolution atm is 640*480. Concerning the processing, this is a webcam based interaction, so it would be non-stop. Though I am not completely sure what you mean. At the moment it does process it for every frame during the time-frame and since the only displayed information is depending on this script, I don't see how I could skip every other frame. Maybe by copying the info? It would give the same lagging feel, would not it? Commented Mar 21, 2019 at 17:39
  • the reason I'm asking about how many pictures you need to process to understand how much optimization would be needed. But yes, whether the processing is non-stop or not may be irrelevant.
    – David
    Commented Mar 21, 2019 at 17:45

1 Answer 1


There are many things that can be done to achieve a performance improvement on a Raspberry Pi. You linked an example using the GPU to achieve better processing speeds. Here is another example that you might want to look at, but it is not a simple solution.

There are many other ways to optimize code, but I am not familiar enough with JavaScript to make a suggestion related to it. However, in general, I'd start by looking at the following things to see if you can apply them to your code:

  • loop unrolling
  • cache optimizations
  • translating some of your code to C

Here are some other links I've found regarding optimizing JavaScript code:

Depending on how much you need to improve your processing speeds, a simple solution would be to overclock your Raspberry Pi.

  • Thanks for your answer. Due to lack of time, I decided to use another, more powerful device. Thus, I could not test the solutions you provided but they helped me make a decision. Commented Mar 24, 2019 at 18:50
  • Absolutely! Best of luck with your project :)
    – David
    Commented Mar 24, 2019 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.