Memory comparaison Sprite and HTML5 img

Not favoritedFavorited Favorited 0 favourites
  • 5 posts
From the Asset Store
Test and challenge your memory in this amazing Christmas themed memory game!
  • Hello,

    I am testing GPU memory usage in a Construct 3 Windows/WebView2 export.

    Test setup:

    - One 4K PNG image

    - 3 HTML <img> elements using the exact same src

    - compared with 3 cloned Construct Sprite object types, each using a copy of the same 4K image

    - Windows Task Manager > Details

    - monitored process: WebView2 GPU Process > Dedicated GPU memory

    Approximate results:

    Baseline:

    - Dedicated GPU memory: ~142 MB

    3 HTML images using the same src:

    - Dedicated GPU memory: ~167 MB

    - Increase: ~25 MB total

    3 cloned Construct Sprite object types:

    - Dedicated GPU memory: ~468 MB

    - Increase: ~326 MB total

    The HTML case appears to share one decoded/GPU resource for the same src. However, the 3 cloned Sprite object types multiply the GPU memory usage of the same image.

    Questions:

    1. Is this expected behavior?

    2. Does each cloned Sprite object type always allocate its own GPU texture, even if its source image is identical?

    3. If I instead create 3 instances of one single Sprite object type, will Construct share one GPU texture between all instances?

    4. Is this also the expected behavior for Tilemaps using replaceImage()?

    5. For large 4K decorative backgrounds/parallax without collision or gameplay interaction, is HTML the recommended memory-efficient approach?

    Thank you.

  • Well, in general the file (png/jpg) is loaded into memory an uncompressed and finally copied into video memory as a texture. In the browser/construct world the image file is loaded into an html img element before it's copied over to a webgl/webgpu texture. Presumably the browser may also load the image to a different texture too if it were to display the image onto the page outside of construct's renderer. However, the exact details of the browser renderer and even construct's renderer are a black box.

    But we can still calculate how much video memory an image would take up. For example, if a 4k image is 4096x2160 then the uncompressed size would be approximately 34mb. (width*height*4/1024/1024).

    1. Seems reasonable that loading three images instead of one would use more memory. For the html image to display it has to load into vram before the browser can render it. The question as to why the amount of vram usage is bigger than we calculate is largely due to the black box nature of the browser and construct's renderer. Maybe they need more textures to composite stuff or whatever.

    2. Yes, when you clone the object types it duplicates the images. Guess you could make a request to have construct check to see if images are duplicated to save memory but that would slow down export times a lot.

    3. Yes, but you could have tested that. Instances of the same type will share textures.

    4. Presumably it loads a new texture.

    5. It's likely more performant to just render everything onto the canvas instead of layering the canvas with html images. Also, you can't do the same things with html images as you can do with sprites. But luckily, you can do whatever you like.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The manual section memory usage has more information about how Construct manages memory. Also when you export, tick 'Deduplicate images' and it will combine identical images, which should ensure only one copy is loaded in to memory.

  • Also when you export, tick 'Deduplicate images' and it will combine identical images, which should ensure only one copy is loaded in to memory.

    I'm actually curious how this works and what exactly it means? How identical do the images need to be? If I have e.g. two sprites with the same image, but one is cropped slightly different, does that matter? I'm assuming it's using some kind of hashing, is there a threshhold where an image that's actually different by a few pixels still gets deduplicated?

  • The images need to be exactly identical: the same size with exactly the same pixel data. There is no threshold - if there was that would act more like lossy compression that could affect your project's artwork.

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