Author Topic: Is NGUI really faster than unity's default dynamic batching? (Performance Test)  (Read 14751 times)

J. Park

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Recently I think about NGUI's geometry rebuild mechanism...
I worry about if it is really efficient than dynamic batching in case many widgets are in motion tweening..
I also found thread like
http://www.tasharen.com/forum/index.php?topic=845.0
http://www.tasharen.com/?topic=ngui-optimization-problem

In case that a UIPanel have many widgets, and most of widgets are moving with TweenPosition,
UIPanel has to rebuild geometry at every frame. I think that it may drop performance.

I have tested with simple code below.
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class demo : MonoBehaviour
  5. {
  6.     public GameObject cube;
  7.     public GameObject btn1;
  8.     public UIPanel panel;
  9.  
  10.     void Start()
  11.     {
  12.  
  13.         for (int i = 0; i < 100; i++)
  14.         {
  15.             GameObject go = NGUITools.AddChild(panel.gameObject, btn1);
  16.             go.transform.localPosition = new Vector3(-400, -240 + i * 4);
  17.             TweenPosition.Begin(go, 10, new Vector3(400, -240 + i * 4));
  18.         }
  19.     }
  20. }
  21.  

It just generate 100 buttons, and tween position from left side to right side of screen for 10 sec.
In Unity Editor of fastest quality setting, it show 150fps for tweening. After tweening, it shows 500-600fps. (About 70% performance drop)

Same test with a cube instead of NGUI widget, it show 450-500fps even with 3 more draw calls. After tweening, it shows 900-1000fps. (About 50% performance drop)

I also check time of LateUpdate() in UIPanel with Diagnotics.Stopwatch in first case(not a same time).
It shows 3-7 ms in Editor, 20-30 ms in Device(Galaxy S)-> hard to get 60fps.

Is NGUI really faster than unity's default dynamic batching (in case that about 100 widgets with a same material are motion tweening)?
« Last Edit: July 02, 2012, 12:53:27 AM by J. Park »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Is it faster? It depends on how you use it. Having it done by NGUI means you have full control over what gets batched and how. This lets you do things like place 2-3 moving widget into their own panel, leaving 1000 other widgets remaining static. In this case yes, NGUI will be way faster.

J. Park

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
For more info, I performed similar test with EZGUI button and iTween, which use dynamic batching.
Definately, NGUI is faster than EZGUI...


Edit 1.
NGUI is not always faster. See a new message below.
« Last Edit: July 01, 2012, 06:44:44 AM by J. Park »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile

jdwieber

  • Guest
I haven't run any performance tests, but I saw at least a 10 fps increase when I dumped Unity's GUI implementation and switched to NGUI.  FWIW, NGUI is also faster and more stable (and useable) than UIToolkit which I also tried out.  I think it really comes down to how well you organize your UI.  Grouping elements that are dynamic together, and static elements is a separate group (panel) will be your best bet.  Also, experiment with the depth pass feature of the panel.

J. Park

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
I haven't run any performance tests, but I saw at least a 10 fps increase when I dumped Unity's GUI implementation and switched to NGUI.  FWIW, NGUI is also faster and more stable (and useable) than UIToolkit which I also tried out.  I think it really comes down to how well you organize your UI.  Grouping elements that are dynamic together, and static elements is a separate group (panel) will be your best bet.  Also, experiment with the depth pass feature of the panel.

I agree that NGUI is much much better than Unity GUI. NGUI have good functionality optimized for UI.
I'm just benchmarking NGUI vs dynamic batching to check an overhead of UIPanel's geometry rebuilding, in case that about 100 wigets are on motion tweening.

Today I performed same test with NGUI and EZGUI (actually EZGUI use default dynamic batching unless managed mode is used) in various quality settings.
The interesting thing is that EZGUI is fater that NGUI in Fastest, Fast and Simple quality settings, even though NGUI is faster than EZGUI in Good, Beutiful and Fantastic quality settings.
I'm afraid that I generally build in Fast or Simple quality setting for a mobile device.
Strange.. but I don't know why...
I'd like to upload sample package but EZGUI don't have free version.
« Last Edit: July 01, 2012, 06:59:57 AM by J. Park »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
As I mentioned, the ideal situation is where you group things based on whether they're static or moving. Try putting 75 of your widgets into a panel marked as "Static" (option on the UIPanel), and remove the script that moves them, leaving the other 25 moving freely on another panel.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
If you're a coding ninja, you can also disable/enable widgetsAreStatic when you need it. I do this for the boost screens in Subway Surfers, where we have to fold out a boost when a user clicks it. It's actually set to static until those a clicked and get set to static after it's done animating.

Of course, to do this you have to be certain when the widgets are not supposed to be static anymore, and when they should be static again, but that's totally doable in most if not all cases.

J. Park

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
I know that NGUI is good enough in a static scene without tween or animation.

But I'm not sure if UIPanel's geometry builiding to bind widgets to make 1 drawcall is more efficient than default dynamic batching in case that GUI have a lot of tweens or animations at a same time.

When I have a chance later, I'd like to test performance more precisely, then I'll give a post