Search Unity

URP in WebGL uses a ton more memory than built-in renderer

Discussion in 'Universal Render Pipeline' started by monark, Sep 1, 2020.

  1. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    I've been developing in URP for a while and I've realised in WebGL it's using a ton more memory than the old standard built in pipeline. Like by almost a factor of 2.

    This appears to be a function of using a separate camera with a different render pass on it.
    So when I start my game I'm using one camera and the memory is stable around 700Mb but then I fire up another camera to do an effect with and suddenly the memory jumps up by 600Mb!
    In the old builtin renderer the memory stayed the same, I was using replacement shaders in that case.

    So does URP duplicate all the object memory when you use another camera with different shaders on it?

    Also, I can't get the profiler to work with WebGL so no information is coming that way.

    Is this a known bug or "just the way it works now"?

    In the editor I don't see the issue, memory stays about the same but in WebGL it's a killer. So my view is it's a bug. Which I'll report.

    I'm currently stuck between a rock and a hard place, do I try and roll everything back to built-in or soldier on hoping for a fix, or keep looking for an existing solution.
    If I roll back I lose the advantages of using the latest pipeline on mobile but it will be less likely to crash in a browser....
    Unity always seems to throw up these conundrums

    Does anyone have any similar experience or insights?
     
    KamilCSPS likes this.
  2. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    162
    Hey there!
    Can you file a bug about this so we can take a look at your project and dig a bit deeper to what's going on?
     
  3. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    You ok with the full project, which is pretty involved, or should I try and reduce it down to something easier to handle?
     
  4. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    I've narrowed down the issue to GetPixels() which I'm calling a few times in a frame to get a pixel area count.
    Weirdly in Chrome on the Mac it doesn't seem to cause an issue, nor does it in a test project.
    But on Windows PC in Chrome on my real project it blows up the memory allocation.

    Case 1274594
     
  5. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    Seems to be related to this, though I'm finding it jumps by 500Mb not 100Mb after 1Gb as stated in this thread
    https://forum.unity.com/threads/wasm-heap-growth.778112/

    I've also managed to refactor some code to improve garbage collection and keep it below the magic 1Gb.