Suggestions on reducing excessive memory usage

0 favourites
From the Asset Store
Memory game, with 10 levels for you to have fun. Made in Construct3, template available for purchase.
  • I'm making a top down shooter which runs reasonably on a moderate spec PC but uses excessive memory. Currently 2.7GB and rising. I've read all the performance improvement articles and blog posts from Ashley but am at a loss as to how I can reduce memory usage beyond what I'm already doing.

    There are a large number of animations in my project (and some large sprite sheets which are between 500kb - 4mb in size) but there are no individual sprites which are larger than 50kb (all images are PNG-24 with transparency). The total size of all spritesheets is 90mb. At its busiest, there are approximately 100-150 sprites on screen. There are some large layouts (10k square) but the number of sprites rarely exceeds 1000 in a layout. Some of these sprites are repeated, so the number of unique sprites generally does not exceed 100 in a layout.

    There are no large layout images, I'm using tiled backgrounds wherever possible, I'm not generating large numbers of sprites via actions or doing anything else (as far as I know) that would consume a large amount of memory.

    The project is too large to share (3000+ events) but any suggestions for reducing memory usage would be appreciated.

  • Are you using the techniques described in Remember not to waste your memory? You must have either an extraordinarily large number of animation frames, or many extremely large images (2048x2048 or larger), to use such an incredible amount of memory. You will simply have to use fewer frames and lower-resolution images. 2.7 GB is so insanely high that many 32-bit devices simply won't have the address space to allocate that much memory. To reach a reasonable range of devices you're looking at needing to cut at least 80% of the memory use of your project.

  • Ashley, yes there are a large number of animations and in some cases, frames per animation. I'm following the techniques described in your article with one exception, and I think this may be my problem. I have around 20 sprite sheets that are larger than 2048x2048 but these contain many frames of animation, (so no single images anywhere near this size). There are some animations with 50+ frames (with each frame being less than 50kb).

    I assumed Construct2 would physically chop up these spritesheets when loading them in as sprite strips in the image editor. If this is not the case, would it help if I broke these large sprite sheets down into smaller sprite sheets? Or do I just have too many frames in my animations?

  • optimize your pictures - 2^n x 2^n for your sprites. also remove transparent edges on your animations - use that trimming option. oh yeah, if you have a designer that made those and once you trim them your animation starts "blinking" or moving away after trimming - it happens because origin points moved. your designer is gonna have to redo the images with as much as possible little transparent space.

    also - use pngoo tool to optimize pngs before insertion, and you can try after but it might cause troubles. / loss of quality is minimal.

    use audio compressor to compress your files by your def. to lowest possible usable - 44khz, 16 bit. ogg format or wav which uses c2.

    also use background tile instead of sprite for huge images (if they're not animated).

    also use groups / rework your code 5x and shorten it as much as possible to achieve the same result. it is possible.

  • you know that screen resolution at fullHD is 1920x1080? your sprite is 2048x2048. so think how to reduce and not lose quality = gg for your big sprites. huge saving.

  • is the 2.7 GB the memory said at the bottom by C2? if so, remember this represents the layouts where, from the lyout view perspective, have the most memory usage, so if you have a dump layout where you put everything, that will say a very high value I guess.

    Animations with 50+ frames, I wonder, are they nessecary, if you can get by with reducing them, it can help.


    "optimize your pictures - 2^n x 2^n for your sprites."

    well no, it is (2^n -2) as C2 will add 1 pixel all around each frame. but you can check if you used the crop option of the image editor for your assets (since you have quite a lot, it may make a big difference). also not using high quality downscaling but medium (you did not mention it, so I guess it is to medium, which is the default).

    could we see one of the 2048x2048 spritesheet to have a better feeling of "can this be striped down with some other techniques" (like if you have 50 frames to represent a spinning ball around a ship, it will be better to make a separate ball, that will be spinning around the ship via events).

  • optimize your pictures - 2^n x 2^n for your sprites

    That's actually the worst size: 2^n - 2 is best, since Construct 2 pads all images with a 1px border round the edge when putting them on a spritesheet.

    There must be thousands of large animation frames to use up gigabytes of memory. It's just a fundamentally inefficient approach to take with your game. You should redesign the project with a whole new approach. Maybe look in to Spriter for creating smooth animations with a very limited set of images. I imagine you are trying to use frame-by-frame animations to create smooth video-like playback, but you just can't do that with frame-by-frame animations without shooting memory use through the roof.

  • 2^n-2 ? funny - i have in my game 3-4 sprites with 360 frames, each is 256x256 - when i export i get 2 sheets with everything on for each sprite.

    i've tried then converting it all to 250x250 - and i got like 6-7 or something even more...

    so you're sayin' if i use 254x254 i would get the best results? Ashley

  • saiyadjin, the frames have transparent edges on the spritesheet but these are trimmed in Construct2. I can rearrange the sprites on the sheets so that so they are (2^n -2), but they will still be very large. Minimal sound in my project so the issues are all image related.

    Aphrodite, the 2.7GB is the "memory use" value in the bottom right of C2. There is a dump layout but it only contains 10% of all sprites. When looking at the memory usage of the nodewebkit executable in task manager it gets close to 2.7GB. Nodewebkit spawns two processes each taking up 1.3GB when the game gets busy. Not sure why this is (using r192).

    Examples of my large spritesheets include cars and furniture (e.g. the same items in different colour schemes). So the large spritesheets are composed of mostly static frames. However, I also have spritesheets for enemy heads (which are pinned to the same body to give enemy variety). Will the whole spritesheet/all frames of animation be loaded into memory for each instance of the sprite?

    Ashley, just to clarify, there are no static frames that are larger than 1024x1024 (max size per frame 200kb), and all frame-by-frame animations are between 2 and 20 frames (max size per frame 50kb). I have looked into Spriter but it can't replicate the look of the complex animations I have hand drawn.

    So my question is, if the sizes of my individual frames are unchanged, is there any reduction in memory usage if I chop up my large spritesheets into smaller sprite sheets and spread the static frames across multiple animations (in one C2 sprite or multiple C2 sprites)?

  • This is my concern too. However, I think avoiding too many large images and repeat small grafics (64x64 / 128x128) to create large enviroment is enough to make a game that runs in any phone. This a guess but would be great to know a range of memory use that would run perfectly in almost all phones in order to not abuse too much and having to redo your project design in the final process of your project.

  • Ashley, just to clarify, there are no static frames that are larger than 1024x1024 (max size per frame 200kb), and all frame-by-frame animations are between 2 and 20 frames (max size per frame 50kb). I have looked into Spriter but it can't replicate the look of the complex animations I have hand drawn.

    I don't think I'll understand this unless you show some examples of the types of animations you are using. But surely you have must hundreds or even thousands of animation frames in total?

    Also when you are stating a size like 50kb, is that just the PNG filesize? As described by Memory usage, the correct calculation to determine the memory usage of a single image is W x H x 4, so a single 1024x1024 frame will use about 4mb of memory alone, regardless of the size of the image file.

  • I assume your game is broken into multiple layouts for different levels?

    If so, save a copy of your project somewhere (so you don't accidental go ctrl+s) and experiment with deleting layouts. The memory usage estimate is based on your most intensive layout (whichever one has the largest variety of objects, usually). You may find that a particular level is chewing a lot more memory than your others.

    Another question is this: are you targeting desktops exclusively? Because, if so, this may be less of a problem. Most modern desktops/laptops have tons of memory; 2.7GB is a lot, but there are games that use much, much more. As you said, node seems to be dividing the memory across multiple processes, so you are unlikely to hit the 32bit limit.

    However, if you were targeting mobile...well, I don't think you are anymore.

    The most memory you'll find in a mobile device is 3-4gb, and that's only for the highest end phones and tablets. With the overhead of other apps and OS processes, your game still wouldn't run. It would probably be more trouble than it's worth to strip down your art to the point where you could sandwich it into a mobile's memory.

  • Sticky for my future reference.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ashley, those are the image file sizes, the C2 size for the player animation frames would be 262kb per frame (256px * 256 px * 4). There are approximately 1000 player/enemy animation frames in total which works out to 260Mb if I'm not mistaken.

    If I add in 300 frames for environment objects per layout, say an average size of 512x512 (some larger, most smaller) that adds up to 300Mb, so rounding up I would expect minimum image memory usage of 600Mb (not including space required for tiled backgrounds which are also used).

    The "ImageMemoryUsage" parameter in C2 varies between 600Mb and 1Gb which seems about right, with I assume the other 1.7Gb (of the 2.7Gb total) being taken up by the code/nodewebkit processes. There is a lot of room for improvement in the code, but I'd be surprised if I could claw back another 1Gb. I can't run the game in a browser any more (too big I assume) so I'm not able to use the layout debugger to troubleshoot.

    I don't think there's much I can do to reduce image memory usage unless I reduce sprite sizes and/or reduce the number of frames.

    Example frames for the player and environment in links below. Edit; Don't have the rep to post links yet.

    TiAm, the game is PC only, so I'm aiming for around 2Gb total memory usage, I estimate half of this will be taken up by image memory, but given I have yet to add audio, I will probably struggle to stay within 2Gb.

  • you know that deduplication happens when exporting and images are added on sheets? still i don't know if sheets are being read from / cut from on usage? how much % do they save ?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)