- Unity 2017 Game Optimization(Second Edition)
- Chris Dickinson
- 350字
- 2021-07-02 23:21:11
Minimize Deserialization behavior
Unity's Serialization system is mainly used for Scenes, Prefabs, ScriptableObjects and various Asset types (which tend to derive from ScriptableObject). When one of these object types is saved to disk, it is converted into a text file using the Yet Another Markup Language (YAML) format, which can be deserialized back into the original object type at a later time. All GameObjects and their properties get serialized when a Prefab or Scene is serialized, including private and protected fields, all of their Components as well as its child GameObjects and their Components, and so on.
When our application is built, this serialized data is bundled together in large binary data files internally called Serialized Files in Unity. Reading and deserializing this data from disk at runtime is an incredibly slow process (relatively speaking) and so all deserialization activity comes with a significant performance cost.
This kind of deserialization takes place any time we call Resources.Load() for a file path found under a folder named Resources. Once the data has been loaded from disk into memory, then reloading the same reference later is much faster, but disk activity is always required the first time it is accessed. Naturally, the larger the data set we need to deserialize, the longer this process takes. Since every Component of a Prefab gets serialized, then the deeper the hierarchy is, the more data needs to be deserialized. This can be a problem for Prefabs with very deep hierarchies, Prefabs with many empty GameObjects (since every GameObject always contains at least a Transform Component), and particularly problematic for User Interface (UI) Prefabs, since they tend to house many more Components than a typical Prefab.
Loading in large serialized data sets like these could cause a significant spike in CPU the first time they are loaded, which tend to increase loading time if they're needed immediately at the start of the Scene. More importantly, they can cause frame drops if they are loaded at runtime. There are a couple of approaches we can use to minimize the costs of deserialization.
- Practical Data Analysis Cookbook
- 深入核心的敏捷開發:ThoughtWorks五大關鍵實踐
- 解構產品經理:互聯網產品策劃入門寶典
- WebAssembly實戰
- Clojure for Domain:specific Languages
- Designing Hyper-V Solutions
- Quarkus實踐指南:構建新一代的Kubernetes原生Java微服務
- JSP開發案例教程
- Serverless架構
- WordPress 4.0 Site Blueprints(Second Edition)
- Rust游戲開發實戰
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- PHP+MySQL動態網站開發從入門到精通(視頻教學版)
- Vue.js 3.x高效前端開發(視頻教學版)
- Learning Dynamics NAV Patterns