CocoonJS memory behaviour, an analysis

Discussion and feedback on Construct 2

Post » Sun Jul 13, 2014 11:52 am

G'day fellow C2 devs.

Due to the lack of documentation on CJS, I was curious about how CJS handles asset loading & memory on startup so I compared the results of two games of mine, Star Nomad & remade Ninja Legacy RPG Defense.

In particular I noticed something odd, Star Nomad takes ~22 seconds to load all assets on most devices and consumed ~155MB of RAM. Ninja Legacy takes ~12 seconds to load and consumes ~125MB of RAM. There is quite a significant load time, which isn't explained by Store services or what not since they both have it. It then dawn on me, all this time I was worried about optimizing image assets to keep the RAM usage low, that this load time can be explained by CJS loading & decompressing audio, all of it, on launch.

It also explains why CJS doesn't need to use preload audio to prevent first sound played lag, like XDK/Crosswalk.

For comparison sake:

Star Nomad only have ~46MB worth of sprite-sheet assets in RAM, following the power of 2 * 4 convention, ie. 64 x 64 x 4 = ~16kB RAM texture, 512 x 512 x 4 = 1MB etc. Ninja Legacy has ~80MB of sprite sheets.

The difference comes down to Star Nomad having a lot more audio tracks, ~10 minutes extra worth of audio music. This causes it to use ~ 60MB more memory minus the sprite differences.

Pretty rough analysis, but it seems 1 minute of audio music = ~6MB in ram, which is pretty huge, not just in terms of memory use, but the fact it has to decompress the audio make your game loads much longer. So for those who weren't aware and working on mobile games, I hope this is helpful.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,614

Post » Mon Jul 14, 2014 5:59 am

Hi silverforce!

The last week I spent a lot of time with cocoonJS and memory usage. I have a really huge game which is just running on latest devices so i decided to improve memory usage.
The main problem is that all images are loaded into memory even though i don't use them on the current layout. I did some research and found a cocoonjs-only function for image objects: dispose(). Unfortunately this function isnt working properly with c2 (couldnt find out why). Currently i try to replace all images with 1px * 1px images.
The idea is to unload all images i don't need and then reload them to the memory when needed. I tried to do this with the largest images and it worked... somehow. At least the game started on weak devices and i could change between layouts. BUT somehow when it reloads the big images again, it crashes.
Maybe you have an idea how to solve this problem?
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Mon Jul 14, 2014 7:51 am

@Vuuv

I have not tried, but what you are doing seem to go against the CJS engine. They can't do loading asset when required (people have been asking for it for years), since their acceleration engine depend on having access to everything, all the time.

I thought it was hilarious that all audio gets decompressed & loaded into memory too, which is just stupid since there's no need for it.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,614

Post » Mon Jul 14, 2014 10:11 am

I replaced all huge images with small images and reloaded them after the game started and this worked. But when i dont need them I want to use the dispose() function to remove them from memory. This doesnt work. Its only possible to replace them with 1px*1px images again but somehow it still uses all memory.
How do you see your memory usage? Cause all my images are shown with 0MB
B
14
S
3
G
1
Posts: 255
Reputation: 2,027


Return to Construct 2 General

Who is online

Users browsing this forum: db3344 and 16 guests