[SOLVED] Application taking 2GB+ of RAM on startup

Hi!

We have a application which is taking a lot of RAM and I’m trying to understand why.

Just for context, it is a single scene, not very large with most assets being loaded dynamically when a websocket event or API call happens.

Looking in windows task manager, whenever I launch the application it raises the Edge process by about 2GB right on startup, by the middle of the default loading bar it starts to ramp up quickly, so I don’t think it is the dynamically stuff doing that. We have most of our assets set to preload, so, to check if the assets were the problem I added this to the loading.js script

app.assets.on('load', (asset) => {
      console.log(`Asset loaded:<<S>> ${asset.name} <<S>> ${asset.file?.size ?? "0"}`);
  });

Taking everything and summing up the size, I end up with 130MB of assets being preloaded, which doesn’t explain the amount I’m seeing.

We have another scene, to test some skins, without all the connection stuff, and the result is a RAM usage increase close to 1.5GB.

Another test I did was to run the performance monitor on Edge, and the result was this:

The Heap JS is pretty high, getting to 1GB, but still far from the 2GB+ I see in the process window.

Lastly, comparing to a standard example from playcanvas, I don’t see much of a increase in RAM usage on those examples, so it is not something standard to playcanvas.

Can someone point me in a direction to understand this behavior?
Thanks!

I’d suggest to start with the Profiler:

But I would guess you might have too many larger textures. Even if your jpg is small, it’s stored in decompressed form in the video memory, in which case the texture compression might help: Texture Compression | PlayCanvas Developer Site

But first use the Profiler to understand what is going on.

Textures can utilize a lot of memory, particularly if you are loading them from images (JPG/PNG/WebP). This is because they need to be decompressed by the browser and then passed to WebGL (again, uncompressed). Ensure you use Basis where appropriate.

Thanks for the responses @mvaligursky @will

I set all my textures to be compressed with Basis and now it takes “only” 1.7GB in the main scene and 1GB in the skin test scene.

And now the profiler looks like this:


Captura de tela 2024-06-25 091712

The VRAM alone doesn’t justify all that size being loaded, right? It seems something is missing yet…

There are some assets that I load from URL in the main scene, is there anyway to better compress it in this case?

when the application is loaded, execute this to true for one frame to get a list of textures with their sizes, that might help:

pc.Tracing.set(pc.TRACEID_TEXTURES, true);

and check the browser console.

I got another problem figured out, I did remove the preload on textures, but not on materials, and templates, so as far as I understood it makes the textures being loaded anyway, that’s why the loading was basically the same.

After tweaking with the editor API in the browser devtools I got to disable most of the preloaded assets from a specific models folder(from 4k+ to ~800 in total) and it helped A LOT with the first load. Then I made the dynamically assets load as needed and the overall RAM usage decreased! It is still somewhat big, but at least it is much clearer why.

Thanks for the help!

2 Likes