"Experience" using profiler tools to analyze memory usage

Source: Internet
Author: User

Unity3d provides us with a powerful profiler for profiling tools. Today we use Profiler to analyze in detail the official example Angrybots memory usage information data.

First Open Profiler Select memory option, in the game run a frame to view the detailed option data (Simple mode of data is very intuitive, you can know that the memory is largely occupied, there are a lot of relevant introduction on the Internet, I am no longer wordy ), As shown in the following:


When selected, Unity automatically obtains this frame's memory consumption data item, mainly divides into: Other, Assets, Builtinresources, Scene Memory, notsaved These five most, below we will analyze each one.

    • Other


Record data items A lot, space time is limited, we select the size of the top of the list of the previous few to analyze it in detail.

    • System.executableanddlls : System executable program and DLL, is read-only memory, used to execute all scripts and DLL references. The values from different platforms and different hardware will vary, and you can adjust the size by modifying the stripping level of the player setting.

Ricky: I tried to change the stripping level doesn't seem to be changing, but it doesn't affect the game if it takes up a lot of memory. Let's ignore it for the moment (--)!

    • Gfxclientdevice: GFX (graphics acceleration \ Graphics accelerator \ Graphics (Graphicsforce Express)) client device.

Ricky: Although it occupies a large amount of memory, but this is also a prerequisite, no way to optimize. Continue to ignore it (--)!!

    • managedheap.usedsize: The managed heap uses size.

Ricky: focus on monitoring the object , do not let it exceed 20MB, otherwise there may be performance problems!

    • Shaderlab: Unity comes with resources related to the shader language tool.

Ricky: This thing is familiar to everyone, ignore it.

    • Serializedfile: serialize files that load resources such as Prefab, Atlas, and metadata in the display into memory.

Ricky: focus on the Monitoring object , here is which presets you want to monitor are used in memory in the serialization, optimized according to requirements.

    • Persistentmanager.remapper: Persistent Data remapping management related

Ricky: related to persistent data, such as Assetbundle. Pay attention to monitoring the relevant files.

    • managedheap.reservedunusedsize: the managed heap reservation does not use memory size and is only used by mono.

Ricky: unable to optimize.

    • Assets


    • texture2d: 2D maps and textures.


Ricky: focus on Optimization objects , the following points can be optimized:

    1. Many textures have a format of ARGB, so the fidelity is high but the memory used is also very large. Without distortion, proper compression of the map, using the ARGB-bit will be reduced by one-fold, if the continued Android with RGBA compressed ETC2 8 bits (iOS with RGBA compressed PVRTC 4 bits), can be reduced by one more. Convert stickers that do not need to be pasted but have alpha channels, all in the format Android:rgb compressed ETC 4 Bits,ios:rgb compressed PVRTC 4 bits.
    2. When a new prefab or map is loaded and is not recycled, it will remain in memory and will not be destroyed even if switching scenes. It should be determined that the object is no longer used or is not used for a long time before the system is empty (null), and then called Resources.unloadunusedassets (), in order to really free memory.
    3. There are a large number of blank atlas maps that can be optimized with tools such as Texturepacker or considered for merging into other sets of graphs.

    • Audiomanager: Audio Manager

Ricky: increases as audio files increase.

    • AudioClip: Sound and sound files

Ricky: The focus is on optimizing objects , which play longer music files that need to be compressed into. mp3 or. ogg format, while shorter sound effects files can use the. wav or. aiff format.

    • Cubemap: Cubic Map Texture

Ricky: This is generally more common in the Sky box, I do not know how to optimize this ...

    • Mesh: model Grid

Ricky: The main check is whether there are duplicate resources, and minimize the number of points.

    • Scene Memory

    • Mesh: mesh models used in the scene

Ricky: pay attention to the number of points in the mesh model and merge mesh as much as possible.

    • Builtin Resources

Ricky: These are some of the internal resources of unity, there is no analytical value for project memory, so I'm not going to analyze it for the time being.

    • Profiler memory focuses on optimization projects

1) Managedheap.usedsize: Mobile games recommended not to exceed 20MB.

2) Serializedfile: The serialized file that is left by asynchronously loading (loadfromcache, WWW, etc.) can be monitored for uninstallation.

3) Webstream: Download the resource file via asynchronous www in the uncompressed version of the memory, a few times or dozens of times times larger than Serializedfile, but we now show no in the project.

4) Texture2d: The key to check whether there are duplicate resources and large memory need to compress and so on.

5) Animationclip: Focus on checking if there are duplicate resources.

6) Mesh: Focus on checking for duplicate resources.

    • Problems you may encounter in your project

1.device.present:

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

2) The 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, so the wait time is very long, for example: excessive assetbundle loading is prone to this problem.

4) Shader.CreateGPUProgram:Shader (Huawei K3v2 Chip) will appear in runtime (non-preloaded).

5) Stacktraceutility.postprocessstacktrace () and Stacktraceutility.extractstacktrace (): Typically caused by Debug.Log or similar APIs, the debug API should be masked after the game is released.

2.Overhead:

1) The general situation is caused by vsync.

2) usually appears on Android devices.

3.GC. Collect:

Reason:

1) Code allocation Memory overload (malignant)

2) A certain time 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)

4.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 gcallow.

3) if (Other.tag = = A.tag) is changed to Other.comparetag (A.tag). Because Other.tag is a GC allow to produce 180B.

4) Use foreach less, because each time the foreach generates a enumerator (about 16B of memory allocation), try to change to for.

5) lambda expression, improper use will result in a memory leak.

5. Use as Little LINQ as possible:

1) Some features cannot be used on certain platforms.

2) A large number of GC allow is allocated.

6. Control the number of Startcoroutine:

1) Open a coroutine (co-process) and allocate at least 37B of memory.

2) Example 21B of the Coroutine class.

3) 16B, enumerator.

7. Connect directly using the StringBuilder substitution string.

8. Cache components:

1) Each getcomponent will be assigned a certain GC allow.

2) 39B of heap memory will be allocated for each object.name.

Ricky Yang Personal Original, All rights reserved, reproduced annotated, thank you. http://blog.csdn.net/yangyy753

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Experience" using profiler tools to analyze memory usage

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.