{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide/",
  "atlas": "https://www.pystone.net/?node=unity-performance-optimization-complete-guide#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide.md",
  "context": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:unity-performance-optimization-complete-guide",
  "slug": "unity-performance-optimization-complete-guide",
  "title": "Unity性能优化全攻略",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "Unity性能优化全攻略",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "cb10334cc30a4cba76716a4d8916bdbc9e34029a7a91828f700ed444fd1dbb06",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "Unity性能优化全攻略",
      "anchor": "unity性能优化全攻略",
      "citation": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide/#unity%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E5%85%A8%E6%94%BB%E7%95%A5"
    },
    {
      "depth": 2,
      "text": "drawcall",
      "anchor": "drawcall",
      "citation": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide/#drawcall"
    },
    {
      "depth": 3,
      "text": "CPU和GPU是如何进行并行工作和交互的",
      "anchor": "cpu和gpu是如何进行并行工作和交互的",
      "citation": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide/#cpu%E5%92%8Cgpu%E6%98%AF%E5%A6%82%E4%BD%95%E8%BF%9B%E8%A1%8C%E5%B9%B6%E8%A1%8C%E5%B7%A5%E4%BD%9C%E5%92%8C%E4%BA%A4%E4%BA%92%E7%9A%84"
    },
    {
      "depth": 3,
      "text": "如何影响性能",
      "anchor": "如何影响性能",
      "citation": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide/#%E5%A6%82%E4%BD%95%E5%BD%B1%E5%93%8D%E6%80%A7%E8%83%BD"
    },
    {
      "depth": 3,
      "text": "DrawCall优化：减少DrawCall",
      "anchor": "drawcall优化减少drawcall",
      "citation": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide/#drawcall%E4%BC%98%E5%8C%96%E5%87%8F%E5%B0%91drawcall"
    },
    {
      "depth": 2,
      "text": "Statistics",
      "anchor": "statistics",
      "citation": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide/#statistics"
    },
    {
      "depth": 2,
      "text": "资源优化",
      "anchor": "资源优化",
      "citation": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide/#%E8%B5%84%E6%BA%90%E4%BC%98%E5%8C%96"
    },
    {
      "depth": 3,
      "text": "声音优化",
      "anchor": "声音优化",
      "citation": "https://www.pystone.net/notes/unity-performance-optimization-complete-guide/#%E5%A3%B0%E9%9F%B3%E4%BC%98%E5%8C%96"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:game-graphics-and-runtime",
      "title": "游戏图形与运行时",
      "url": "https://www.pystone.net/notes/game-graphics-and-runtime/",
      "atlas": "https://www.pystone.net/?node=game-graphics-and-runtime#knowledge-atlas",
      "label": "游戏图形与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "游戏性能优化中的“Unity性能优化全攻略”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#%E6%B8%B8%E6%88%8F%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96"
    }
  ],
  "contentMarkdown": "# Unity性能优化全攻略\n\n> 创建时间：2020/4/23 17:16\n\n**标签：**|  _优化_\n\n## drawcall\n\n就是cpu对图形绘制接口的调用，CPU通过调用图形库（directx/opengl）接口，命令GPU进行渲染操作。\n\n### CPU和GPU是如何进行并行工作和交互的\n\n### 如何影响性能\n\n每一次绘制CPU都要调用DrawCall，而在调动DrawCall前，CPU还要进行很多准备工作：检测渲染状态、提交渲染所需要的数据、提交渲染所需要的状态。\n而GPU本身具有很强大的计算能力，可以很快就处理完渲染任务。\n当DrawCall过多，CPU就会很多额外开销用于准备工作，CPU本身负载，而这时GPU可能闲置了。\n\n### DrawCall优化：减少DrawCall\n\n## Statistics\n\nFPS超过30，就不卡（每秒渲染多少帧）\nCPU：进行计算的绝对时间值\nbatches：对某些drawcall进行合并，合并成一批\nVerts：摄像机视野中的顶点数\nTris：三角面个数\nSetPass calls：Shader中包含很多pass\n\n## 资源优化\n\n### 声音优化\n\nDecompress On Load\n在硬盘上压缩这个文件，并在第一次加载到内存的时候解压它，这是加载声音文件的默认选项，大多数情况下我们应该使用这个选择 。\n加载后解压缩声音，声音文件将在他们加载不久后就解压，这个选项适用于较小的压缩声音，以避免即时解压缩的性能开销。要知道在加载时解压 Vorbis编码的声音将使用的内存是压缩状态的十倍或更多（ADPCM编码大概3.5倍）所以不要使用此选项用于大文件。\nDecompress On Load 默认选项适用于小文件。\nCompressed In Memory\n保持声音在内存中是压缩的并在播放时解压缩。这有更多的CPU开销（尤其是OGG / Vorbis格式的压缩文件），但可以提高加载速度并减少内存消 耗，因此这个选项适用于大文件。 在性能窗口可以看”DSP CPU”。\nCompressed In Memory 适用于大文件。\nStreaming 选项\n直接从磁盘流音频数据。这只使用了原始声音占内存大小的很小一部分。 该方法使用最少的内存和最多的CPU，它有个很明显的缺点就是不能被引用超过一次。试着让 Audio Clip产生多个副本的时候会每个都产生数据缓冲区，如果非要这么做会产生大量的内存和cpu消耗。因此这个选择最好是给单实例的Audio Clip，如背景和环境音效。对于手游而言不要优先考虑使用这种方式。\n————————————————\n版权声明：本文为CSDN博主「CZandQZ」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。\n原文链接：<https://blog.csdn.net/u012565990/article/details/51794486>\n"
}
