Hacker News new | ask | show | jobs
by Zev 4774 days ago
It wasn't mentioned in the article, but, it is very important to note: CAGradientLayer is not GPU-backed.

In other words, the comparison is between the CPU redrawing a gradient 60x a second, and, an image being moved around on screen. Not entirely surprising that the one that does less rendering is going to be faster.

2 comments

CAGradientLayer is absolutely GPU-backed. Your colors and locations are drawn into a 1-D texture and stretched on the GPU.
Yes, one should always set shouldRasterize on CAGradientLayers (or at least those that aren't in a parent that has shouldRasterize)
Saying "Always rasterize" isn't necessarily the solution, either. Its actually pretty bad advice to follow all the time ;)

I suspect (but can't confirm without the source code to the demo) that shouldRasterize would actually hurt performance in one of the two cases in the article. Specifically, I imagine that it would make the score for adding and removing views from screen even worse than it already is.

Yes, it renders into a bitmap, and reduces CPU usage, once you've paid the upfront rendering cost. But, it doesn't rasterize opacity, and, will use up a ton of memory (because it doesn't result in stretchable images).