Execution speed of code in render function

Hello folks. I’ve been having fun playing with the my new Pixelblaze for the past few weeks now and at the point where I’d like to understand an observation that I don’t see explained anywhere here (or couldn’t find it anyway).

Code in the Render function seems to run a lot slower than code in the Before Render function. I’m curious why that is. I have moderately complex code in the Before Render function that runs lighting fast, but even simple code in the render function bogs down the frame rate pretty quickly. I would imagine that all the render function is doing is filling up an array(s) corresponding to each pixel and, in the background, the machine cycles through the arrays to light the pixels at the configured data rate. Such an array presumably can be created in the Before Render function and the array entries called using the index in the Render function, and that would run at a much higher frame rate for some reason. I’m curious what that reason is. Or, maybe, my eyes and brain are fooling me, and my observation is wrong.

The code should run at the same speed, but code in render runs once per pixel instead of once per animation frame.

If your code only needs to selectively update a few pixels states it may be more efficient to update an array in beforeRender.

1 Like

That makes sense. When I think about that, executing multiple statements in the Render function for each of 100 pixels is two orders of magnitude slower than once per frame. 270 Mhz speed effectively becomes 2.7 Mhz, but the execution speed is the unchanged. Thanks, wizard. It hasn’t been a limiting issue for me, but it’s useful to understand and now I do.