I have a small project I'm working on that handles a VERY large array (1024 items), outputting the data from the array to 1024 separate elements on the doc (yes, i tried canvases, but they're too blurry for what i'm doing).
What I need is some way to optimize this loop as much as possible.
for(var i = 0; i < 1024; i++){
elems[i].style.height = data[i] + 'px';
elems[i].style.backgroundColor = 'rgb(0,' + data[i] + ',' + (255 - data[i]) + ')';
}
For every item in the array data, which is always 1024 items long, the loop sets the height of one of the 1024 div's on the page stored in elems, along with setting its color to be more green for larger values, and more blue for lower values. The values inside data always range from 0 to 255. The loop is run every animationFrame and I cannot make it go in sections over time. The data must be updated live.
My main issue is that running the loop outputs a VERY low FPS count, usually around 15fps. My question is:
In what ways can I optimize the loop above to run a fast as it possibly can? The data is updated live every render frame. I'm going for high FPS as my main target. Is this possible?
If it helps, I'm making a music visualizer with the new Google Chrome audio analyzer.
I can also see this helping for whenever I need to crunch or display very large datasets in the future as well. Every method, even if largely unreadable (that's what /*comments*/ are for), helps!