Author Topic: UIRect.OnEnable mega Lag  (Read 5312 times)

alexeyshevchenko

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
UIRect.OnEnable mega Lag
« on: June 11, 2014, 06:16:57 AM »
Hi
Does anybody know how to optimize UIRect.OnEnable in NGUI?
when I show the shop window I have a big lag, for example on IPad 3 the window opens for 2 seconds

In Unity profiler i see that method UIRect.OnEnable eat 85% of CPU.

And for now it seems that useing UIRect.OnEnable for disappears it have more CPU then for showing

And for now to hide panels need more CPU work than for instantiate its.

 :-\  :-\ :-\ :-\ :-\


downlod new ngui 3.6.3

run test

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class testbtn : MonoBehaviour {
    public GameObject pref;

    List<UISprite> gos = new List<UISprite>();

    public  void OnClick() {
        if (gos.Count == 0) {
            for (int i = 0; i < 2000; i++) {
                GameObject go = NGUITools.AddChild(gameObject, pref);
                int ix = Random.Range(-400, 400);
                int iy = Random.Range(-400, 400);
                go.transform.localPosition = new Vector3(go.transform.localPosition.x + ix, go.transform.localPosition.y + iy, go.transform.localPosition.z);
                gos.Add(go.GetComponent<UISprite>());
            }

        }
        else {

            foreach (var v in gos) {
                v.enabled = !v.enabled;
            }

        }
       
       
    }
}


TURNS instantiation FASTER THAN JUST EVEN hide objects, it is planned to do something or not?
« Last Edit: June 11, 2014, 06:23:02 AM by alexeyshevchenko »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIRect.OnEnable mega Lag
« Reply #1 on: June 12, 2014, 01:56:36 AM »
I gave your script a try. 227 ms to instantiate, 192 ms to enable, which makes sense. Whenever you instantiate something, it will still run its OnEnable. For my test I created a sprite, saved it as a prefab, and that's what I was instantiating. If I was instantiating panels, results would likely be quite different.

alexeyshevchenko

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UIRect.OnEnable mega Lag
« Reply #2 on: June 18, 2014, 03:50:04 PM »
I gave your script a try. 227 ms to instantiate, 192 ms to enable, which makes sense. Whenever you instantiate something, it will still run its OnEnable. For my test I created a sprite, saved it as a prefab, and that's what I was instantiating. If I was instantiating panels, results would likely be quite different.

judging by http://www.tasharen.com/forum/index.php?topic=7708.0, this is a problem v3
roughly since version 3 ngui not suitable for mobile games

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIRect.OnEnable mega Lag
« Reply #3 on: June 18, 2014, 05:15:43 PM »
You create 2000 widgets on the fly and it takes 200 milliseconds to create them, then conclude that NGUI 3 is not suitable for mobile games? Interesting logic there.

If you get lag when showing your shop window, then reduce the amount of content you show on your mobile device. Seems logical, doesn't it? How many thousand widgets do you have there? It's a mobile device. Limited resources. This is why most mobile games separate content into pages or at the very least -- tabs.

alexeyshevchenko

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UIRect.OnEnable mega Lag
« Reply #4 on: June 19, 2014, 06:15:31 AM »
You create 2000 widgets on the fly and it takes 200 milliseconds to create them, then conclude that NGUI 3 is not suitable for mobile games? Interesting logic there.

If you get lag when showing your shop window, then reduce the amount of content you show on your mobile device. Seems logical, doesn't it? How many thousand widgets do you have there? It's a mobile device. Limited resources. This is why most mobile games separate content into pages or at the very least -- tabs.

 Hi

I'm attaching screenshots to all my comments to prove I'm not making it up.

As you can see, there are only 68 sprites on my scene.

Here's another screenshot: instantiating 68 sprites takes about 100mc on my core i7 PC 0o!!
On ipad the same amount of work takes more than 3 seconds!

Also just after the sprites are activated, the garbage collector is started and it consumes lots of time

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIRect.OnEnable mega Lag
« Reply #5 on: June 19, 2014, 06:16:44 PM »
You have your console log full of errors -- null reference errors at that. You don't think that will cause serious performance degradation? Fix your errors then give it a try again.

For comparison try the same thing with the Menu example that comes with NGUI (Example 3). When you click the Options button, it shows a new screen. It takes about 2 milliseconds to activate it. My profiler window looks quite different from yours as well in terms of functions called. UIRect.Start() is the function that gets called N times, where "N" is the number of widgets. What version of NGUI are you using?
« Last Edit: June 19, 2014, 06:28:40 PM by ArenMook »