Search Unity

PostLateUpdate.PresentAfterDraw on CPU Profiler

Discussion in 'iOS and tvOS' started by saiichihashimoto, Aug 16, 2017.

  1. saiichihashimoto

    saiichihashimoto

    Joined:
    Apr 18, 2017
    Posts:
    5
    Unity: 2017.1.0f3 Personal
    XCode: Version 8.0

    I've built my game on Android and WebGL and, performance-wise, they're great. However, when I build for iOS, the profiler is completely enveloped by PostLateUpdate.PresentAfterDraw. The game lags a tremendous amount and I can't find any reference to the function.

    upload_2017-8-16_11-31-58.png

    The other profilers show nothing of note. I'm willing to debug this issue, but I'm not sure how to go about it without random guessing as to what could be causing it. Is there a more specific reference as to what this is?
     
    Kekaku, ow3n and ykeyani like this.
  2. ykeyani

    ykeyani

    Joined:
    Dec 28, 2015
    Posts:
    20
    Hi I've been having the same issue, what I've found is that PostLateUpdate.PresentAfterDraw is most likely related to physics. By disabling most of my colliders the lag disappears so that could be a starting point for optimising the game for iOS.
     
    Last edited: Aug 19, 2017
  3. saiichihashimoto

    saiichihashimoto

    Joined:
    Apr 18, 2017
    Posts:
    5
    upload_2017-8-17_14-13-22.png
    I just removed every collider and rigidbody in my scene (except 3 of them), as a test. It didn't budge at all.
     
  4. ykeyani

    ykeyani

    Joined:
    Dec 28, 2015
    Posts:
    20
    Very strange, simplifying my colliders cut it in half for me.
    The only other possibility I can think of then is that it is related to either co-routines or threads, PostLateUpdate is probably being called at the end of every frame and may be running code in co-routines, my colliders were being assigned in a co-routine after being generated in a thread so that could be it.

    You could also try switching your script call optimization to fast in player settings/other if you haven't already and disabling accelerometer too if you're not using it.
    I'll see what else I can do but there's not much information about it.
     
    Last edited: Aug 19, 2017
  5. ykeyani

    ykeyani

    Joined:
    Dec 28, 2015
    Posts:
    20
    After analysing the profiler in xcode and comparing frame times and doing some tests I have completely eliminated the issue.

    PostLateUpdate.PresentAfterDraw represents gpu frame times and by switching to more simple shaders the frame time will reduce. In my case my custom shader was too complex for the limited gpu resources.

    So I would recommend first trying something like Mobile/VertexLit to confirm that it's the shaders and then go about trying to simplify them, for me it's a case of de optimising for better gpus and reducing pixel drawing.

    This video has a ton of useful information for xcode:


    Final note: I don't think its mentioned in the video but putting as much code as possible in your vertex function will massively improve performance, and capturing gpu frames in xcode will give you all the information you need to optimize your shader (Its actually amazing, better than anything else I've seen for shader profiling).
     
    Last edited: Aug 19, 2017
    ow3n likes this.