Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Downloading a 250MB File Causes "Out of Memory" Error

Discussion in 'WebGL' started by NoBullIntentions_P, May 24, 2020.

  1. NoBullIntentions_P

    NoBullIntentions_P

    Joined:
    Jul 2, 2012
    Posts:
    311
    I'm trying to port a mobile app to WebGL and I'm struggling a bit with memory/storage. Specifically, I download a 250MB zip file to Application.persistentdatapath, which I understand uses IndexedDB internally.

    In Edge, this works fine but in Chrome, I get the "Aw snap" error with the error code "out of memory". At this point, developer tools shut down so I can't be sure, but I don't see anything out of order in the javascript console. Smaller zip files work fine so there's no problem with the logic. I increased the heap size by 250MB and it still crashes, which makes sense since it shouldn't really be in the heap since I'm streaming the download to a file, not loading it all in memory at once.

    Now there's a long pause after the file finishes downloading and I don't know if that's relevant. I disabled "data caching" just in case but this doesn't make any difference. I have plenty of free hard drive space so I don't think Chrome is struggling to find enough space for a 250MB file.

    I've read through the WebGL memory management article on the blog too but it's very out of date and doesn't offer any insight on this particular problem. At least, not to me.

    Now, I *could* upload the contents of the zip to a folder and download each file separately and that might well mitigate or fix the problem. And it's not terribly inconvenient. But I don't want to work around a problem I don't fully understand when I'm still relatively new to WebGL (but not Unity.) I'd much rather get a proper understanding of what's going on when I write a 250MB zip to persistentdatapath, why it causes a problem, why only on Chrome, and how to go about fixing it. In the future, I may need a single file which is 250MB and when I do, not using a zip won't change anything.
     
  2. wetcircuit

    wetcircuit

    Joined:
    Jul 17, 2012
    Posts:
    1,409
    To unpack a zip, the browser will need to have enough room to hold both the zipped file and its unpacked contents in memory at the same time (probably more because there's other things in your project, like the Unity engine).

    Every web browser handles its memory cache a little differently, some are more strict.
     
  3. NoBullIntentions_P

    NoBullIntentions_P

    Joined:
    Jul 2, 2012
    Posts:
    311
    The error happens before I even think about unpacking it so that's not an issue here. If I just downloaded the contents of the zip separately, an individual file might end up being 250MB. I will still need to know how to download that file without crashing the browser.

    I appreciate that the implementation will vary between browsers but I will nevertheless need to know how to negotiate this correctly and what specifically the issue is.

    • Does "Aw snap, code "out of memory" always indicate a particular type of memory allocation that's failed? Is there any way to determine which?
    • Is there any way to determine the available amount of storage available of whichever type of memory it's running out of before downloading the file?
    • Assuming, it's not heap memory (which it seems not to be) then is there any way to request higher allocation?
    • Are there any memory management/allocation issues with Unity 2018.3 that would make it necessary to upgrade to 2019.x?
     
  4. Tom-Mensink

    Tom-Mensink

    Joined:
    Jul 27, 2017
    Posts:
    17
    I have the same issue with writing large files (also around 250 MB) to the persistent data path in WebGL. I use this to cache files downloaded from a server. So any solutions appreciated. Using Unity 2019.4.8f1
     
  5. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    94
    Same to me. In Unity 2020.1, when unpacking a 150mb asset bundle, it needs around 2gb of ram when unpacking. Maybe more, but then chrome crashes. In firefox there are no problems at all.

    So, why does it need way more ram than the unpacked asset size to unpack the asset bundle? And why only in Chrome?
     
  6. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944
    A limit of 250MB in desktop(?) 64-bit(?) Chrome sounds indeed surprisingly low. If someone can build a small test case and report it as a bug, I'd be curious to take a look if there's something fishy going on.
     
  7. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944
    I have created a test application that can be used to gauge the maximum WebAssembly application memory size. You can find it here: http://clb.confined.space/dump/mem_growth.html

    When testing, tap the button on the page until memory heap size no longer increases.

    I would be curious to know what kind of results people get on different mobile devices, especially whether the results differ if one has a few tabs open, or when there is only one tab open; and whether mobile browsers crash with Chrome's "Aww, snap." dialog or similar.
     
  8. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    552

    Unable to allocate 512.000 MB
    Heap size is now: 501.063 MB (525,402,112 bytes)

    Using chrome 88.0.4324.93 (Official Build) (32-bit)
    On Android 10, Galaxy S10e
     
    jukka_j likes this.
  9. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944
    Thanks. My Huawei P10 Plus caps at 678.123MB (711,065,600 bytes), Chrome 87.0.4280.141, Android 8.0.0

    Interestingly, Firefox browser on the same device is able to do full 2GB Wasm heap. (that is the max that Firefox on any OS is able to do atm.. Chrome on desktop can do up to 4GB)