Why is BitmapData.clear() so slow?

Recommended Posts

I'm seeing a massive performance hit from BitmapData.clear(). I've also noticed it eats up memory. I looked at the source code and the bottleneck appears to be from setting the dirty flag to true. If I use BitmapData.context.clearRect() manually, everything works fine. What is the dirty flag doing? Why is it necessary to set it? Perhaps an argument could be added to skip setting it?

Share this post

Link to post
Share on other sites

Which version of Phaser are you using?

In 2.4.4, I see that clear calls BitmapData.update, which is documented as being very expensive. However, that was removed in 2.4.5. If you aren't using 2.4.5 or 2.4.6, try updating Phaser and see if you still get the performance hit.

Share this post

Link to post
Share on other sites

To answer your question about what the dirty flag does:

BitmapData.dirty is checked in BitmapData.render, which "will push the texture up to the GPU if it's dirty." I didn't go further, but you can check it out if you are interested.

I'll bet your performance issue is related to BitmapData.update though.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.