Search Unity

EventSystem.Update() causes spike in CPU only on the initial touch / click

Discussion in 'UGUI & TextMesh Pro' started by StayThirsty, May 1, 2015.

  1. StayThirsty

    StayThirsty

    Joined:
    Jul 6, 2013
    Posts:
    42
    Why does the EventSystem.Update() take so long to process for the first initial input touch / click ?
    Profiling my game on Android shows that the initial EventSystem.Update() takes about 200ms to complete and generates a few KB of garbage.... I tested a brand new empty project with just a button and it's the same thing. High % of cpu usage for the initial touch then breezes through the rest of the clicks.

    I disabled the EventSystem and instead made a simple script :
    Code (CSharp):
    1. ...
    2. void Update()
    3. {
    4.       if ( Input.touchesCount > 0 )
    5.       {
    6.             someGameObject.transform.position = Vector3.zero;
    7.       }
    8. }
    And there's no hiccup as expected. However, with some additional testing I noticed there was still a hiccup if I added a debug.log message like so :

    Code (CSharp):
    1. ...
    2. void Update()
    3. {
    4.       if ( Input.touchesCount > 0 )
    5.       {
    6.            // would cause a slight hiccup on initial touch as well...
    7.            Debug.Log("something");
    8.       }
    9. }
    Any ideas? I'm curious about this but I won't mind creating a dummy button that will process the first click and progress with the rest of the game smoothly...


    Thanks!
     
    dginovker and roointan like this.
  2. djfrail

    djfrail

    Joined:
    Jan 16, 2014
    Posts:
    124
    I'm also seeing this happen. Testing on an old Kindle Fire.
     
  3. StayThirsty

    StayThirsty

    Joined:
    Jul 6, 2013
    Posts:
    42
    Unfortunately I haven't come across a solution other than making an unavoidable button to take the first hiccup. :( :(
     
  4. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Am I late? Well, you can trace this with "DeepProfile" in Profiler. Basiclly it could be ANYTHING because it's not a single call, take a look then you will know what's going on there.

    Tips: In most case, it's your Button.OnClick event invoke a slow function.
    Tips2: You can't really rely on those time displayed in DeepProfile mode since this mode have significant effect on that, so use this mode wisely.
     
    Last edited: May 30, 2016
    irenjie likes this.
  5. shohan4556

    shohan4556

    Joined:
    Feb 3, 2016
    Posts:
    11
    I am also having the same issue how did you solved this
     
  6. Geads

    Geads

    Joined:
    Aug 24, 2017
    Posts:
    45
    Bump. 1st touch 12kb of GC and 200ms delay
     
  7. Defikush

    Defikush

    Joined:
    Aug 13, 2018
    Posts:
    1
    Unity 2019.1 , just the first touch anywhere on the screen on Android causes 250ms of lag from EventSystem.Update(), tried disabling all of my canvases, nothing makes it better.
     
    dginovker and Eater_Games like this.
  8. austinborden

    austinborden

    Joined:
    Aug 5, 2016
    Posts:
    24
    In my case the lag was caused by Mono.JIT. Building the Android player using IL2CPP fixed it for me.
     
    prabhukaran likes this.
  9. roointan

    roointan

    Joined:
    Jan 8, 2018
    Posts:
    78
  10. prabhukaran

    prabhukaran

    Joined:
    May 5, 2019
    Posts:
    17
    Mono build causes the lag. IL2CPP build fixed it for me as well. And I disabled the "Raycast Target" for the objects which doesn't need it. This will reduce the EventSystem effort/Update.
     
    PiP0w likes this.