Flash high CPU usage in idle state
I have commited a bug report to Adobe about the high cpu usage in Flash applications at idle state.
Please vote for this bug, so it has higher chances to get fixed soon.
There is also another bug report by Grant Skinner regarding the same issue.
Here is a copy of the bug report (if you are too lazy to register @ Adobe š ).
Steps to reproduce:
1. create a hight number (>1000) of displayobjects and add them to the stage (visible area)
2. set the framerate to a hight value (>50)
3. move the mouse over the stage and donĀ“t move it (idle state)
Actual Results:
idle cpu usage (taskmanager) is quite high (>10%) depending on the framerate, cpu and number of displayobjects
Expected Results:
in idle state there should be nearly no cpu consumption (in AS2 -> AVM1 it was quite low)
Workaround (if any):
reduce the framerate, set mouseEnable and mouseChildren to false whenever possible
Here is a detailed discription and testresults:
Problem:
We are working on a huge flex application (170 000 lines of code) and run into some performance problems.
We have set the framerate to 60 fps and the cpu consumption of the application was about 20% on a 3Ghz quadcore machine. there were no user interactivity and rendering going on.
So we investigated the problem.
After setting the framerate to 25 fps and setting the mouseEnable and mouseChildren property to false at the displayObjects where we donĀ“t need mouse interactivity, we got an acceptable cpu consumption in the idle state. I am still wondering for the reasons for this behavior and specially for the different behavior in comparison to the old virtual machine (AS2). A strange observation was also that when moving the mouse over a textField the cpu consumption goes down to 0%.
Test situation:
I Create 2000 displayObjects and add them on the stage (visible area). I give the flashplayer (standalone flashplayer 10.0.r12, release version) the focus and put the mouse over the playerwindow. I donĀ“t move the mouse and there is no rendering going on. The cpu consumption is quite high depending on the framerate.
The same test scenario with AS2 (AVM1) does not show such a high cpu consumption.
When I set mouseChildren at the stage to false the cpu consumtion goes down to 0%. Setting the mouseEnabled property at every Sprite to false has just a small effect on reducing cpu consumption. I tried it also with a container sprite in which all the 2000 sprites where added, setting the containers mouseChildren to false also reduced the cpu consumption radically. The same when I set mouseEnabled of the container AND of all Sprites to false but donĀ“t set mouseChildren of the container to false. Setting mouseEnabled of all Sprites to false but not at the container has only a small effect. Seems like the flashplayer recognize if no children has mouseEnabled set to true and then donĀ“t need to traverse throught the displaylist.
For me it seems that the flashplayer has to check every frame for the mouseEnable properties and this consumes resources. If mouseChildren is set to false it has not to go further up the displaylist, so this is much faster.
Regarding the TextField: As long a the selected property is set tot true it reduces cpu consumption down to 0%. It seems that when moving the mouse over a selectable textField that the flashplayer donĀ“t has to check any other displayObjects for mouse interactivity.
In the flex profiler I have seen an high growth of the consumed time by [reap] (98%) and Timer.tick (1%). ([reap] is an internal process: Flash Player reclaims DRC (deferred reference counting) objects.)
I am wondering which changes in the AVM2 has causes these problems and if there are options for optimizations. I am also wondering why there is no event based (like os interrupts) model possible, it seem that the flashplayer has to check every frame for possible os input (mouse move,…).
I am also wondering if the strategy I have seen in the flex frameworks core classes to set the framerate up to 1000 fps for speeding up rendering and then reset it to the original framerate, could has negative side effects due these behavior.
Could it be that it is related to the native support for the mouseWheel event passed from the os to the flashplayer? Because this was a change from the old virtual machine, where the mouseWheel where not passed to the player.
Test results:
AS3 code (-> AVM2)
AS3: framerate 24:
mouse over the stage: 3%
mouse over the textField: 0%
mouse over the one sprite: 3%
mouse over the stack of 1000 sprites: 3%
AS3: framerate 120:
mouse over the stage: 9-14%
mouse over the textField: 0%
mouse over the one sprite: 10-13%
mouse over the stack of 1000 sprites: 14-18%
AS3: framerate 1000:
mouse over the stage: 36-40%
mouse over the textField: 0%
mouse over the one sprite: 22-40%
mouse over the stack of 1000 sprites: 17-33%
AS2 code (-> AVM1)
AS2: framerate 24:
mouse over the stage: 0%
mouse over the textField: 0%
mouse over the one sprite: 0%
mouse over the stack of 1000 sprites: 0%
AS2: framerate 120:
mouse over the stage: 6%
mouse over the textField: 0%
mouse over the one sprite: 6%
mouse over the stack of 1000 sprites: 6%
AS2: framerate 1000:
mouse over the stage: 8%
mouse over the textField: 0%
mouse over the one sprite: 8%
mouse over the stack of 1000 sprites: 8%
Environment:
Flashplayer 10.0.r12 (release version)
OS: Win XP pro SP2
3Ghz Singlecore
2 GB Ram
AS3 code:
stage.frameRate = 1000;
for(var i:uint = 0; i < 2000; i++)
{
addChild(getSprite());
}
var tf:TextField = new TextField();
tf.x = 120;
tf.width = tf.height = 100;
tf.text = “test”;
addChild(tf);
var s:Sprite = getSprite(0xFF0000);
s.x = s.y = 120;
addChild(s);
function getSprite(col:uint = 0x00FF00):Sprite
{
var sprite:Sprite = new Sprite();
with(sprite.graphics)
{
beginFill(col);
drawRect(0, 0, 100, 100);
endFill();
}
return sprite;
}
AS2 code:
this.frameRate = 1000;
var i:Number;
for(i = 0; i < 2000; i++)
{
attachMovie(“mc”, “mc”+i, i);
}
this.createTextField (“tf”, ++i, 120, 0, 100, 100);
tf.text = “test”;
i++;
var mc:MovieClip = attachMovie(“mc”, “mc”+i, i);;
mc._x = mc._y = 120;
source file:
http://bugs.adobe.com/jira/secure/attachment/27527/idleCpuTest.zip
Comments (3)
Category: Actionscript,Flash,Flashplayer
Comment by AndrewBoldman
Made Thursday, 4 of June , 2009 at 20:21
I really liked this post. Can I copy it to my site? Thank you in advance.
Comment by Manfred Karrer
Made Saturday, 6 of June , 2009 at 10:16
@andrew: why not use a link? but copy it if you like…
Comment by Hamed
Made Friday, 8 of October , 2010 at 16:24
hi, recently we did a project with flash cs5(as3) in which we should new some MovieClip and remove them after a while and so many Tween animation ….
i have a 2.5 gigHz cpu and the application use 50% of it
it was terrible
i am working on flash for many years i dont know what to do! we should distribute this application to many peaple! which have lower cpu configuration… what should i do? i’m going crazy!!
Sorry, the comment form is closed at this time.