Search Unity

Feedback Each Particle System takes up ~ 112KB after being serialized in prefabs locally in Unity 2018.4.10f1

Discussion in 'General Graphics' started by sunwangshu, Jan 15, 2020.

  1. sunwangshu

    sunwangshu

    Joined:
    Mar 2, 2017
    Posts:
    21
    Hello!

    I recently figured out that there are prefabs of tremendous sizes in our project, somewhat above 1.3MB. In my impression, prefabs are usually of 1KB-ish size.
    After looking into the serialized files, it looks like Particle System is the culprit.

    I first removed two particle systems from a prefab, and the file size decreased by 225KB.
    Then I created a new GameObject in the scene, only added a particle system to it, then made it a prefab. It took up 114 KB in total.
    So that means one particle system takes up roughly 112KB.

    And, by checking the GameObject.prefab in the second test, it looks like the file is mostly made up of particle system related settings. It expanded from line 5 all the way to line 4700.

    I wonder if this gets fixed in later versions? And does it affect runtime efficiency too?

    Using Unity 2018.4.10f1 currently. Thanks : )
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Hi,

    We are looking at ways to reduce this, but haven't managed to find a robust solution yet.
    The problem is we include lots of redundant information for all the particle properties that support different modes (curve, 2 curves, constant, etc)
     
    sunwangshu and karl_jones like this.
  3. jannysice

    jannysice

    Joined:
    Jun 8, 2017
    Posts:
    11
    This is a very annoying issue for us. We did some benchmarks and found that for our project, particle systems affect load times on runtime and overall build times for asset bundles significantly. It took 8 minutes less to build asset bundles ( down from ~ 18 minutes ). I don't have good data for the load times yet but it noticeably improved for scenes that used to have a lot of particles.
    On top of that particles make up 80% of the prefab file size. It contributes 31 megabytes to the overall download size of our android builds.
    I manually removed the serialized data for disabled particle system modules in all prefabs and it drastically reduced the file size. Of course the data gets put back once you save the prefab again but it just did it to see what it would do to the file size.

    I would suggest to add a feature where you can opt in to not serialize disabled modules. I think in the normal case modules don't get enabled by code on runtime. That would already give most of the benefits.
    To me that seems like an easy change that doesn't break backwards compatibility.

    Looking forward to a response. Thank you.
     
    sunwangshu and Rich_A like this.
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    We do have some work to reduce the amount of redundant data, unfortunately, it has some issues which we have not managed to resolve yet. We are also considering making modules optional as you suggest. Unfortunalty I have nothing concrete I can offer you at the moment, just that we are aware its an issue and want to find a solution.
     
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Even if you had a fix available, chances that it lands in 2018.4/2019.4 LTS are pretty much zero I assume?

    I thought Shuriken is considered legacy already and doesn't receive much attention anymore. I thought all resources go into VFXGraph. That's not the case?
     
    karl_jones likes this.
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    No, it's not Legacy!
    VFX team does have more resources but we are still working on Shuriken. There are still benefits to each system and no reason to deprecate Shuriken at the moment(CPU vs GPU etc).
    You are right about the backporting to 2018.4/2019.4 though. A change like this would be too high risk and be classed as a feature which means that the earliest you would see it now would be 2021.1+.
     
    sunwangshu and Peter77 like this.
  7. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    I just looked at the .prefab file what's actually stored. Excuse me if I'm going to point out the obvious.

    It seems mostly curves cause the bloat. Every module contains at least two curves (minCurve, maxCurve). I imagine many curves might be left at their default values.

    Getting rid of the default curves might significantly reduce the bloat. If module stripping is too difficult, perhaps curve serialization is the easier route to go?

    I've of course no idea how serialization in Unity work, so my assumptions are likely to simple. But from an outsiders perspective, when serializing the file, one could check if it's a "default min or max curve". If it's a default curve, "set it to null" for serialization, so it does not end up in the file. If the deserializer detects "a null curve", create the corresponding default min/max curve for it.
     
    sunwangshu likes this.
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Yes, thats what we have at the moment. It still has some issues. We prototyped a version that removes modules vs one that removes redundant curve data and the curve one was only marginally bigger but still a big saving. So we will likely go down the curve path as it makes more sense and requires no additional UI, properties or extra user input.
    There's a lot of edge cases that crop up when you only serialize certain parts. For example, the editor and SerializedProperties can not handle it, presets have problems with the concept of optional parameters and prefab patching also struggles(crashes). We also need upgrade paths when reading old serialized data. We have been working through these issues but im sure theres more edge cases that will come and bite us :(
    The good news is that we did manage to solve the issues that were blocking us yesterday. So one step forward :)
     
    Last edited: Jul 17, 2020
    sunwangshu and Peter77 like this.
  9. HoangVP

    HoangVP

    Joined:
    Jan 12, 2022
    Posts:
    1
    Is there update on reducing the ParticleSystem serialized data, please ?
     
  10. KimmoFactor

    KimmoFactor

    Joined:
    Dec 29, 2020
    Posts:
    39
    Just stumbled upon this in my project, and yes +1 to fixing the bloat, serialized particle systems seem to be massively full redundant data.
     
  11. AlcoleponeHome

    AlcoleponeHome

    Joined:
    Jun 9, 2018
    Posts:
    47
    requesting a update on this, i think it would help download size of a lot of android and ios app's....

    @karl_jones
     
  12. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
  13. AlcoleponeHome

    AlcoleponeHome

    Joined:
    Jun 9, 2018
    Posts:
    47
    @jannysice how did you strip the module data out? I'm editing the text file of the prefab to delete modules, but the build size is unchanged,

    @karl_jones does the build process add the missing data again?
     
  14. skykevin9

    skykevin9

    Joined:
    Jun 13, 2019
    Posts:
    7