Search Unity

Bug Huge performance regression in Enter Play Mode with lots of Sprite Atlases (Case 1243023)

Discussion in '2020.1 Beta' started by mahdi_jeddi, Apr 30, 2020.

  1. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    166
    I'm experiencing huge performance regression in entering the play mode if the project has a lot of sprite atlases / PSB files even when running an empty scene. I'm using the new "Enter Play Mode" settings to prevent scene/domain reload. In our project we're now at 17+ seconds on our fastest machines (8700K, 64GB RAM, SSD).

    This is completely destroying our process and is making it really hard to work. It all seems to come from Unity not caching the atlas bakes in the memory and loading them from disk constantly:

    Screenshot_2.png
    Screenshot_3.png

    And then there is this new annoying "Hold On" message that is adding to the wait without seeming doing anything in the background. It even shows up when I'm trying to delete a few files or move around assets:
    Screenshot_1.png

    I had high hopes for the new Asset Pipeline to improve our import/load times, but I think sacrificing the "Enter Play Mode" speed and other immediate tasks inside Unity for it is a very bad tradeoff. I would gladly wait longer for the project to load than having to wait 17 seconds each time I hit the Play button or 10 seconds to remove a few files.
    I thought that this is because our project is too big (which runs fine on older Unity versions), but even an almost empty project shows this before running the game.

    I hope this is just a bug and not "By Design" and gets fixed before the beta phases ends, because it would make it really painful to work in Unity.
     
    Last edited: Apr 30, 2020
  2. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    166
    I watched the Unite videos on the new asset pipeline and its design goals, and I think it's the right direction for Unity to pursue. I also understand that the old system had a long time to become mature and is optimized so many times so this is somewhat expected. It's just a little bit scary that this is the first taste of the system especially in beta branch that is usually closer to release than the alpha branch.

    Hopefully things get a lot better as they move towards the final version and Unity takes their time releasing a stable version like 2019.3.
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,703
    mahdi_jeddi likes this.
  4. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    166
    Good stuff, but doesn't seem to be our problem. The regression for us is in entering play mode without leaving Unity, or switching to another application or making any changes to assets or scripts. I'm just entering the play mode again right after I exited it, but see a huge delay. A little bit of history for this regression:
    • In 2019.3 beta we got the new options not to reload scene/domain which made the "Enter Play Mode" for us almost instantaneous (< 1 second).
    • On Unity 2019.3.0f3 they fixed a problem in SpriteAtlases so it wouldn't save the hashes inside the asset and make the files dirty when running the game in different machines. And that fix I suppose created this regression and added around 6 seconds of delay even when using to Asset Database V1.
    • In later versions of 2019.3 (12 for example) things got a little bit better, and now we have 4 seconds of delay.
    • On Unity 2020.1b7 I'm getting 4 seconds of Editor freeze just to get to the "Hold On" message which goes on for another 13+ seconds.
    This last one is where it's really unacceptable, 4 seconds is still not bad but 17 seconds is just crazy, and has to be some kind of bug somewhere in the pipeline, especially considering that these "Hold On" messages are now everywhere.
     
  5. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    166
    Looking at the profiler, I can see that Unity is reading every single atlas file to see if they changed and it needs to recompile them before entering the play mode which is fine, but not when absolutely nothing in the project has changed.

    I think a simple optimization to the caching of atlases, so that it wouldn't get cleared if nothing relevant has changed, could fully solve this problem and we'll go back to instantaneous playmode.

    Another way to solve this is to give us a button to compile the sprite atlases manually. It's already possible to completely turn them off in Editor, so making it an option shouldn't be much of a problem. The only reason we use the sprite atlases in Editor is because without them the game would run really slowly and would be unplayable (we have a lot of hand-drawn animations what would take a long time to load without atlases).
     
  6. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    86
    Hey @mahdi_jeddi

    After talking to the 2D team, there's been a fix to this issue is available since Unity 2019.3.11f1

    However, if you're still experiencing issues with the editor being slow I'd be happy to hear if there's something the Asset Database can do better, in your opinion :)
     
    mahdi_jeddi likes this.
  7. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    166
    The fixes until now haven't affected our situation, so there may be something special about our project that make this issue worse. I already sent the whole project for reproducing the problem we have.

    In previous versions of Unity, we could enter playmode almost instantly, which has turned into 7-10 seconds because of the sprite packer checking the whole project, and it's getting worse as we add more assets.This may never be solvable because the asset database traversal may always be this slow.

    Right now there is only 2 options: completely disable the atlases, which would make the game run at really slow speed because of all the texture loading and it would crash when run out of memory. Or try to build the atlases each time I want to enter the playmode. I think the best solution would be to add an new option to editor settings to let us manually pack the sprite atlases. This way, I would be able to have full control over this, and if we have API access I could make a editor for it to pack the atlases when needed.
     
  8. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,171
    I don't know if it is Sprite Atlas that is causing in my case but I do also feel the entering start mode has become considerably slower for 2020. I do use Atlases.

    I usually click on the preview packing button right after adding the sprites to the atlas anyway, so having option to somehow caching the atlas and manually packing sounds good to me.
     
  9. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,703
    The issue reported in this thread has been fixed already:
    • Fixed in Unity Editor version 2020.2.0a8, 2019.3.11f1, 2020.1.0b9 and above.
    https://issuetracker.unity3d.com/is...tering-play-mode-even-if-no-changes-were-made

    If you still see enter playmode being slower, I would submit a new bug-report, so Unity can take another look at your specific case.
     
  10. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    2,521
    The team was able to reproduce this issue. It is being tracked here: https://issuetracker.unity3d.com/product/unity/issues/guid/1252917/
     
    Peter77 likes this.
  11. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    166
    I just tested the Unity 2020.2.a16 that has this fix. It's now on par with the Unity 2019.3 performance but not as good as 2019.3.0f1 or beta versions that would enter playmode immediately. The editor is still accessing all of the thousands of atlas files each time before entering the playmode.

    Aside from giving us manual access to sprite packing, I'm interested to see what the new V2 of atlas packer will offer. I'll check it out.
     
  12. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,171
    I have tested 2020.2.a16 but its playmode entry time is still very much aweful. Especially on debug mode. almost like 2x or 3x slower than 2019.
     
    mahdi_jeddi and ROBYER1 like this.
  13. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,138
  14. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    166
    The new V2 sprite atlas packer just crashes when I turn it on. Filed a bug report with reproducible project: Case 1260508
     
    ROBYER1 and LeonhardP like this.
  15. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    166
    Mine is now exactly as it was on 2019.3 after the patch that made things really slow. It's still way better than what it was at the start of 2020.1. Hopefully they can fix it to make it instantaneously again.
     
  16. natereesedev

    natereesedev

    Joined:
    Jul 6, 2020
    Posts:
    10
    Is this going to be fixed in 2020.1? or is it exclusively a 2020.2 fix? Seems to make 2020.1 unusable or significantly worse for all 2D / UI heavy projects.
     
    ROBYER1 likes this.
  17. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    166
    Just updated to 2020.2.0a19. Enter playmode for me went down from 8 to 5, which is already pretty good. Unfortunately the new sprite packer didn't improve things at all. Editor reads every single atlas file before entering playmode, which I was hoping the new packer would not do.

    QA told me that this is a 2020.2 only fix, and they're not planning to backport it. Maybe they do it if enough people ask them. 2020.1 is pretty awful for me, but thankfully 2020.2 is pretty stable, and the fastest since 2019.3, so you should try it if you're not planning a release soon.
     
  18. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    2,521
    Good news, the fix will be backported to 2020.1. It could land as early as 2020.1.3, but that is just an estimate.
     
    ROBYER1 and mahdi_jeddi like this.
  19. DanielTanBK

    DanielTanBK

    Unity Technologies

    Joined:
    Aug 20, 2019
    Posts:
    14
    Which sprite atlas version are you using?
    • Sprite Atlas V1 will still have to check every atlas file for dirtyness (even if no change is made) and repack if needed. If the project is huge, the recommended V1 packing option would be "Enabled For Builds" and not "Always Enabled".
    • Sprite Atlas V2 does not need to check.
    Additionally, a fix for the related bug you mentioned(1260508) has been released in 2020.2.0a19
    Issue Tracker Link: https://issuetracker.unity3d.com/issues/2d-spriteatlas-v2-editor-crashes-when-packing-sprites
     
    Unity_Javier likes this.
unityunity