unity定位瓶颈

定位是脚本问题还是渲染问题:https://learn.unity.com/tutorial/diagnosing-performance-problems#5c7f8528edbc2a002053b598

    帧率 fps,毫秒。 知道哪些耗时较长比较关键。 哪些部分降低帧率则优化那部分。 记录profile数据,分析数据。掉帧因为完不成。怎么profile?cpu usage里能看到每部分的时间。总时间。hierarchy view看具体信息。对比不同帧。timeline:不同线程,主线程、

渲染线程、worker线程。  找原因:1. 垂直同步,会影响帧率,我们先排除。先在profile隐藏掉它,点它的方格、hierarchy里忽略waitForTargetFPS,关掉它:

Edit Project Settings > Quality. From the drop-down menu labelled VSync Count, select Don’t Sync.  2. 渲染:cpu渲染什么,gpu去渲染;gpu usage profiler:看两个时间,如果gpu时间超过cpu时间,则是gpu受限。
 
 

如果用不了gpu usage profiler(有的平台不支持),观察cpu使用,cpu是否在等gpu完成任务。cpu usage里切到层级模式,选TIme ms,降序排列。如果Gfx.WaitForPresent占的时间最长,表示是cpu在等gpu。gpu bound。

看是否是cpu bound:看上面颜色,哪种颜色占比大。去层级哪里,选time ms列,排序,看哪个文件消耗大。

gc:garbage collection。gc Alloc时间

物理:复杂物理计算是否是性能元凶,cpu usage里面的physics,看看物理占用的时间是否特别长,再去下面的层级里看是否有物理的函数消耗特别大。优化物理:https://docs.unity3d.com/Manual/iphone-Optimizing-Physics.html

脚本:检查慢或复杂的脚本是否是性能糟糕的元凶。cpu  usage profiler里的Scripts部分。注意:ImageEffect、OnWillRenderObject、OnPreCull函数在cpu usage profiler里是rendering data的一部分而不是script。

 https://learn.unity.com/tutorial/diagnosing-performance-problems#5c7f8528edbc2a002053b597

原文地址:https://www.cnblogs.com/Shaojunping/p/12800658.html