Hello.
It seems that UIPanel stores it's vertex buffers as static, meaning they are shared between all UIPanels. The comment in code says 'Cached in order to reduce memory allocations'.
This creates massive performance issues when two or more panels are active at the same time, and they both have some animated widget that requires redraw.
For example, Panel A is a normal panel and Panel B is a sub-panel set up with clipping for a UITable or UIGrid. They are both active at the same time. In both panels A and B, you have a UILabel that animates its color every frame. This animation forces both panels to re-draw and rebuild their buffers every frame.
Since the buffers are all using NGUI's BetterList, they theoretically should be re-used and therefore minimize allocation. But the problem is exacerbated when the vertex count of Panel A and Panel B is very different.
For example, Panel A has 100 vertices and Panel B has 2000 vertices. When the panel submits its draw call (UIDrawCall::Set), setting the mesh's vertices requires calling BetterList::ToArray, which is then forced to call BetterList::Trim to resize the buffer.
When Panel A and Panel B get updated every frame, they will basically fight one another for the shared (static) UIPanel vertex buffers. Panel B will constantly need to re-alloc a larger buffer for 2000 vertices, and Panel A will constantly need to trim down to 100 vertices, causing large alloc and GC problems.
I've temporarily solved the issue locally by removing the 'static' modifier on the UIPanel's buffers. While this technically increases my initial alloc count, it gives me much smoother and stable performance overall.
Is there a better way to solve this issue (other than not animating the labels...)?
Thanks!
