Search Unity

Memory use profiler: 300MB, Webpage inspector: 2.8 GB!?

Discussion in 'Web' started by Jelmer123, Oct 7, 2019.

  1. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    243
    Hi

    I'm trying to optimize memory usage of my game. I know that everything in WebGL gets loaded into the memory. But how to find out what is using up space? What's confusing me most if the difference between the profiler (292.7 MB memory, connected to a development build in the browser) and the inspector in a browser (2.8 GB, also for non-dev builds).
    I'm using engine code stripping and don't know what else to do or what to look for?
     

    Attached Files:

  2. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Additional in-browser memory profilers that are useful:
    - In Firefox, open the Unity page, and then in a background tab, navigate to about:memory and do a snapshot there.
    - In both Chrome and Firefox, you can snapshot the JavaScript heap to get a breakdown of where memory is used in detail.

    If the tools give cryptic looking results, try pasting a screenshot here (or link to a build) - I can see if I can decipher it for you.
     
    Jelmer123 likes this.
  3. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    243
    In Firefox it says it's about 500Mb, 99% of which is some array(?)
    I can't post the build here publicly as it's for a client and not finished yet..
     

    Attached Files:

  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    That 494 MB is taken up by the WebAssembly heap, i.e. basically the Unity engine code. Note that it is just a memory reservation, not all of that memory is necessarily in use. You can gauge the amount in actual use by dividing the Unity profiler usage by the total heap size, e.g. 281.8MB / 494 MB = 57%.

    You can preallocate the heap to a specific size by applying an Editor script with a statement like

    PlayerSettings.WebGL.memorySize = 320; /*megabytes*/

    That will help do a "tighter" reservation that might not overcommit as much.

    However the 2.8GB memory usage from your first post reads like something completely different - WebAssembly heap has a max size of about 2GB, so you may be looking for some other source here.
     
    Jelmer123 likes this.
  5. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Jelmer123 likes this.