openfl 3.1.2
lime 2.4.8
platform: iPad 4 / safari
I’m getting some weird behavior in HTML5 target regarding CPU usage.
First of all, if I simply load up a blank openfl project (screen is black) it continuously burns 30% CPU. If I do the same test with just some basic JS that loads and shows an image, it uses 0%.
If I run my entire game; I have the following (odd) results:
- I have a line of code that loads a list of images (png). All images are small on their own but there are over 100 of them.
- I have another line of code that simply calls addChild( myBitmap ), which shows a full-screen image to the screen. This bitmap is not an image in the above-mentioned list of images that gets loaded (it is loaded before this step).
- I have a small audio library that loads, which seems to permanently add 5% on top of all that (but I am neglecting this item going forward).
So here’s the curious part: if both of those lines are enabled, I get a continuous additional 50% CPU burn on top of that original 30. So my CPU usage remains in the low 80s. If I comment out ONE of those lines (ie, don’t load my list of images OR don’t render a single bitmap image) I get the 50% back! So if one (either) or both are commented, I get 50% back. If both are present, it eats 50% CPU on what is a static splash screen consisting of a single background image and a single button image.
I methodically tested my own code in various systems to rule them out, and I’ve been trying to find the causal link here. Using the browser profiler, I see there is a lot of activity in render (which eventually triggers context.drawImage() ). It seems there is something that causes the entire canvas to constantly be invalidated and need to constantly update. I’m not seeing any early termination conditions in render to optimize performance.
To reiterate, if I show a bitmap and don’t load these files, there is a 0% CPU hit. If I load these files and don’t show a bitmap, there is also a 0% CPU hit. If I both load and show there is a 50% hit.
I noticed in the master branch on openfl’s github there have been some changes to BitmapData.draw and Bitmap, which are arguably the two classes triggering these performance issues. I also see calls from CairoTextField and CairoBitmap that are causing some performance hits.
So my question here is: Is loading somehow displaying all my loaded materials offscreen or would it effect flagging the canvas as dirty?? Why is the entire canvas redrawing with every update on a static screen?
Please let me know if I can be more helpful with testing or info. Maybe I can export the browser profile so you guys can load it up and inspect it. I’d love to help you all figure this out. I know I’m a little stumped since so much happening in the background.
Thanks so much!!!