Search Unity

Where to change heap size?

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

Thread Status:
Not open for further replies.
  1. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    243
    In this Unity blog post, it states that the heap size can be changed in build.js. However, build.js is not present in my generated webgl solution.
    in UnityLoad.js I did come across 3 definitions of new ArrayBuffer(...) but I'm not sure if that's the one to change (?). Slightly hard to make sense of the code there ;)

    In the Unity manual, it says it should be under player settings. I don't see it there either.

    What am i missing here? :)
     
    Last edited: Oct 20, 2019
  2. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    You can change the startup WebAssembly heap size using an Editor variable. Check out the attached build script for example, and the line "PlayerSettings.WebGL.memorySize = 256;" in it.

    Note that for WebAssembly builds, this is just the initial size, and at runtime the size can grow. In asm.js builds the size is fixed to the value specified in memorySize variable.
     

    Attached Files:

    ismaelnascimentoash likes this.
  3. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    That blog is outdated; unless if you're making an asm.js build you don't want to touch the default (32MB) memory heap size for wasm. With wasm we can now finally grow the memory heap without performance concerns (this was a huge problem "back in the day" with js).

    You want to keep the heap size small because (IIRC, not 100% sure) this is also the size Unity/emscripten will grow your heap. So suppose you set the heap to 512MB in the player settings and then use 513MB on your heap in a real build, Unity will then try to allocate an extra 512MB (a total of 1024MB) even though you just need a little bit more. I'm pretty sure this is why it was removed from the GUI player settings; it's already set to the optimal amount.
     
    Jelmer123 likes this.
  4. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    243
    Ah ok, I got so confused about the old blog posts. Thanks for clarification!

    In my game, I still get an out of memory with certain builds in Safari and Chrome, I suppose I'm hitting the max possible memory useage? Chrome says heap size is 893MB, but I'm loading asset bundles in the background, so maybe there was a memory spike (?)
     
  5. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    It's hard to say really without understanding your project and your testing environment. I'd just note that 32-bit browsers (doubly true on 32-bit operating systems) and mobile (iOS/Android) browsers can be quite difficult and will definitely struggle with that heap size. The size of your asset bundles can also play a large role. It's a bit of a balancing act: you want your bundles to be broken up so it's easier on the heap but not so broken up that they blowup your loading times. Do you have huge monolithic bundles? Try breaking them up if possible.
     
  6. Magendanz

    Magendanz

    Joined:
    Sep 8, 2015
    Posts:
    7
    I have about 50 students learning Unity with 2D Game Kit that are hitting this issue, and the only workaround I've been able to share with them is to edit the TOTAL_MEMORY in the .json file. This is an intro course pitched as zero-code, and so this ugly workaround is proving a problem. Any suggestions on better ways to publish 2D Game Kit projects via WebGL without hitting the Out of Memory errors (which happen on both Chrome and Edge browsers)?
     
  7. thuong_henry

    thuong_henry

    Joined:
    Mar 4, 2020
    Posts:
    6
    what is file .json name ?
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    This (necroed) thread is years old. Please look at the dates of posts before replying.

    All three of your posts now are necros.

    Thanks.
     
    KamilCSPS likes this.
Thread Status:
Not open for further replies.