Search Unity

Question WebGL memory peak on load causes a crash with no assets

Discussion in 'Web' started by minDog, May 29, 2023.

  1. minDog

    minDog

    Joined:
    Oct 21, 2021
    Posts:
    3
    I've been experimenting with memory management in WebGl builds in 2021.3 and 2022.2, and have run some tests. I built an app that has literally no assets, but a big codebase. I noticed that even with code stripping set to max, there is a huge initial spike in memory usage (measured with --memory-profiler flag and FireFox profiler).

    An empty app spikes at about 200 MBs on load. But an empty app with a big codebase (just .cs libraries, no plugins) and code stripping enabled, goes up to 600-800 MBs when the app is being loaded. If I throw in some assets - I get a crash, as that number goes above 2GB.

    Can someone explain to me why that is. Is every line of code an app has compiled to webassembly, right? So for example, if my code simply references a lot of namespaces and language features, all of that is being loaded up and added to the initial heap that the browser has to deal with?

    What are the strategies to mitigate that initial peak of memory usage?