官术网_书友最值得收藏!

Minimizing 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 and all of their components, as well as 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 anytime 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 dataset 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 datasets like these could cause a significant spike in CPU the first time they are loaded, which tends 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.

主站蜘蛛池模板: 正蓝旗| 万山特区| 闽清县| 定日县| 红安县| 东阳市| 金湖县| 阿城市| 邵阳县| 饶平县| 吉安市| 凤山县| 海兴县| 昔阳县| 永泰县| 绥阳县| 崇仁县| 舟山市| 尼玛县| 神农架林区| 应用必备| 平陆县| 苍溪县| 杭锦后旗| 澄江县| 望江县| 灌阳县| 迁安市| 咸宁市| 黄陵县| 呼伦贝尔市| 广宁县| 澳门| 定西市| 明光市| 沅江市| 乐平市| 武功县| 米泉市| 河东区| 绥中县|