Targeted Unity optimization with profiler

Source: Internet
Author: User

Ext.: http://user.qzone.qq.com/289422269/blog/1453815629?ptlang=2052targeted Unity optimization with profiler1. CPU usage

A. Waitfortargetfps:

Vsync (vertical sync) function, which displays the CPU wait time of the current frame

B. Overhead:

Profiler overall time-the total record time for all items. Used to record unclear time consumption to help further refine profiler statistics.

C. Physics.simulate:

CPU elapsed time of the physical simulation of the current frame.

D. Camera.render:

CPU consumption of the camera rendering readiness

E. Rendertexture.setactive:

Sets the rendertexture operation.

Bottom-level implementation: 1. Colorsurface and Depthsurface of the current frame and the previous frame.

2. If these two buffer matches do not generate a new RT, otherwise a new RT is generated, and the corresponding viewport and spatial transformation matrices are set.

F. Monobehaviour.onmouse_:

Used to detect input message reception and feedback of the mouse, mainly including: Sendmouseevents and dosendmouseevents. (As long as the edtor is open, this will exist.)

G. Handleutility.setviewinfo:

In editor only, the function is to match the display in the GUI and editor to the display of the published version.

H. GUI. Repaint:

GUI Redraw (description in the use of native Ongui)

I. Event.internal_makemastereventcurrent:

Responsible for the GUI message delivery

J. Cleanup Unused Cached Data:

Empty unused cache data, mainly including Renderbuffer garbage collection and textrendering garbage collection.

1.rendertexture.garbagecollecttemporary: In Renderbuffer garbage collection, clear the temporary freetexture.

2.textrendering.cleanup:textmesh Garbage Collection Operations

K. application.integrate Assets in Background:

Traverse the pre-loaded thread queue and complete the load, and finish loading the texture, substance update, and so on.

L. Application.loadlevelasync Integrate:

Load the CPU of the scene, usually if the time is long, 70% of the texture is likely to be too long.

M. Unloadscene:

Unloading gameobjects, component, and Gamemanager in a scene is generally used when switching scenes.

N. Collectgameobjectobjects:

The Gameobject and component in the scene are aggregated into an array while executing the above m items. Then perform the following destroy.

O. Destroy:

Remove CPU usage for Gameobject and component.

P. Assetbundle.loadasync Integrate:

The content in multi-line preempted Awakequeue, which is the awakefromload function for multithreaded execution of resources.

Q. Loading.awakefromload:

Called after the resource has been loaded, each resource is processed against its application.


2. CPU usage

A. Device.present:

Device. The time-consuming display of presentframe, which appears in the release version.

B. Graphics.presentandsync:

Display and vertical synchronization on the GPU is time consuming. This option appears in the release version.

C. Mesh.drawvbo:

The rendering of the vertex Buffer object on the mesh in the GPU is time consuming.

D. Shader.parse:

The parsing process of the engine to shader after the resource joins.

E. Shader.creategpuprogram:

Build GPU engineering based on the graphics library supported by the current device.

3. Memory Profiler

A. Used Total:

The sum of the current frame's unity memory, mono memory, gfxdriver memory, profiler memory.

B. Reserved Total:

The system requests memory at the current frame.

C. Total System Memory Usage:

The amount of virtual memory used for the current frame. (usually 1.5~3 times we currently use memory)

D. gameobjects in Scene:

The number of gameobject in the current frame scene.

E. Total Objects in Scene:

The number of objects in the current frame scene (except Gameobject, component, etc.).

F. Total Object Count:

Object Data + asset number.

4. Detail Memory Profiler

A. Assets:

Texture2d: Records the texture resources used in the current frame memory, including textures for various gameobject, Sky box textures, and lightmap resources used in the scene.

B. Scene Memory:

Records the memory footprint of each aspect of the current scene, including Gameobject, resources used, various components, and Gamemanager, which are not shown here in the case of assetbundle loading.

A. Other:

Managedheap.usesize: The heap memory allocation that is caused by the code at run time, indicating the amount of heap storage allocated by the last GC to date.

Serializedfile (3):

Webstream: This is a memory footprint that is loaded by www.

System.executableanddlls: Different platforms and different hardware will not get the same value. ******************

5. Optimization Focus

A. CPU-GC Allow:

Principle of concern: 1. Detect any one-time memory allocation greater than 2KB option 2. Detects options that have more than 20B memory allocations per frame.

B. Time MS:

Record the CPU usage per frame of the game runtime (pay special attention to more than 5ms).

C. Memory Profiler-other:

1.managedheap.usedsize: Mobile games are recommended not to exceed 20MB.

2.SerializedFile: The serialized file that is left when loading asynchronously (Loadfromcache, WWW, etc.) can be monitored for uninstallation.

3.WebStream: Download the resource file via asynchronous www in-memory decompression version, more than Serializedfile large or dozens of times times, focus on monitoring. * * * *

D. Memory profiler-Assets:

1.Texture: Focus on checking whether there are duplicate resources and large memory needs compression.

2.AnimationClip: Focus on checking for duplicate resources.

3.Mesh: focus on checking for duplicate resources.

6. Issues that may be encountered in the project

A. Device.present:

The 1.GPU Presentdevice is really time-consuming and generally appears in the use of very complex shader.

The 2.GPU runs very fast, and because of the vsync reason, it takes a long time to wait.

3. This is also the reason for VSync, but other threads are very time consuming, which results in a long wait time, such as an excessive assetbundle load that is prone to this problem.

4.shader.creategpuprogram:shader will be stuck in the runtime phase (non-preloaded) (Huawei K3v2 Chip).

B. Stacktraceutility.postprocessstacktrace () and Stacktraceutility.extractstacktrace ():

1. Typically caused by Debug.Log or a similar API.

2. The debug API should be masked after the game is released.

C. Overhead:

1. The general situation is caused by vsync.

2. Usually appears on Android devices.

D. GC. Collect:

Reason: 1. Code allocation Memory overload (malignant) 2. A certain interval is called by the system (benign).

Occupation time: 1. Related to existing garbage size 2. Related to the remaining memory usage particles (such as excessive scene objects, low utilization, the GC will need to do a memory rearrangement after release)

E. Garbagecollectassetsprofile:

1. The engine performs the unloadunusedassets operation (the operation is time-consuming and is recommended when cutting the scene).

2. Avoid using the unity built-in GUI as much as possible to avoid gui.repaint transition gc Allow.

3.if (Other.tag = = Gearparent.mogoplayertag) changed to Other.comparetag (

G. Lambda expression, improper use can result in a memory leak.

H. Use less LINQ as much as possible:

J. Connect directly using the StringBuilder substitution string.

K. Cache components:

2. Each object.name allocates 39B of heap memory.

Targeted Unity optimization with profiler

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.