Improve Neopixel Peformance? #1028
Replies: 16 comments
-
Posted at 2018-06-09 by user90787 Actually, just ran a test, the framerate is dropping to 12fps when the code is executed - otherwise it runs at 33fps.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-06-09 by Wilberforce Looks to me line 19 there is still a console.log. Why don't you push the frame rates into an array and dump that at the end or in a timeout that happens say once a minute? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-06-11 by @gfwilliams Logging in Puck.js (when you're connected via Bluetooth) really slows things down (25ish FPS sounds about right) - so that would definitely be something to avoid doing often. When you're not connected it should be ok, but then there's not much point having them :) Neopixel writes should be pretty much as fast as they can get, however the actual JS code execution speed isn't huge, so that alone could be slowing things down for you. If you want to log speed I'd do:
So then you're only doing a print every second, which shouldn't affect the speed. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-06-13 by user90787 Sounds interesting - any references I could take a look at to wrap my head around this concept? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-06-14 by DrAzzy This is a problem with espruino for animations... Remember the pingpong light project? (Which worked - there are 8 strings around my room of 10 lights each.) On esp8266's running espruino. Why only 10 per string? Js execution speed on the esp8266 controllers. Not that the esp8266 is the fastest microcontroller in town, of course |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-06-14 by @gfwilliams
In the code above? Rather than printing for every frame, you just increment a counter. Then every second you print the value of that counter. If 30 frames were rendered in that second then it should print 30. If you're asking about the JS execution speed then http://www.espruino.com/Performance might help though |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-07-01 by maze1980 While it's an old thread, starting with the code provided
I tried to optimize, and see what's possible:
The duration measured is included in the code sample, and it's obvious that the neopixel write itself is fast, there's no optimization needed. However filling every array index and calling Math functions makes things slow. To avoid this I did the following:
This code is 10x faster. However you should note that [].concat() returns a standard array with three (or four) UInt8Arrays inside. (concat and splice are not implemented for UInt8Arrays, so you can't use these functions). Running this code with standard arrays more than doubles the execution time. When doing rainbow effects or other smooth animations you would want to use UInt8Arrays as containers for RGB values, and standard arrays for these containers (if you have enough variables and RAM available). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-07-02 by @allObjects ...line # 18 will never be executed... Since you have a complete filled loop, you can let go of the loop of 1..<10... just do the line. Furthermore, require is a lookup - fast but still a look up, therefore get it into a variable at the beginning w/ |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-07-02 by @gfwilliams You can have a preallocated |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-07-02 by maze1980 @allObjects: Line 18 doesn't matter as it was just used to get an idea of the execution time simulating some random merging of per-calculated values. I'll use the require(), that's good. @gordon: I didn't get what function do you mean using ".set". I'd say setting RGB values at runtime is most likely too slow in most cases. Having this thread resurrected, I did a quick rainbow implementation.
If you have any suggestions on how to make the code faster please give me a hint. And if you want it to https://www.espruino.com/WS2811 feel free to copy it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-07-02 by @allObjects @maze1980, regarding line #18: lines 17 and 18 have the same condition... so #18 was never used. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-07-02 by maze1980 I know, it's a copynpaste of the "else if.." line for about 10 times to do compare the speeds (mainloop with rgb color calculations vs mainloop with merging arrays). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-07-03 by @gfwilliams I mean instead of
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-07-03 by maze1980 Thanks Gorden. It's a nice function and really fast. Just tried it with a pixel runner left/right.
Execute at your on risk, epilepsy warning. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-07-03 by @MaBecker what about replace |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-07-03 by maze1980 Actually the prepare function isn't used and needed, the array is initialized with 0 values. I should have removed the function. If any other value but zero was needed .fill would be faster and shorter than using a loop, indeed. Thanks for the info. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2018-06-09 by user90787
I've got a 24 Led ring which I'm able to control successfully from Puck.js. The FPS, however, is a little 'meh'. I am using setInterval at an interval of 1 milli (just to see if that speeds it up any) and it looks like it's running around 20-25-ish FPS. Also, I don't have anything logging to the console (I noticed that slowed things down some).
Is there any way to either increase the speed at which the pixels refresh over SPI or is there a better method than setInterval to provide a little more FPS to the leds?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions