Since the project needs to render a large number of characters on the same screen, I needed to improve Flash Player’s rendering performance. This afternoon I ran a rendering performance test and polished up the bitmap optimization library I wrote last year.
Screen size 2880*2880
500 vector character animation MCs (nested 2 levels deep), looping playback
None of them removeChild off-screen regions
All tests run with the Flash Player SA 10.0 debug build
- No optimization, straight addChild
fps=4, CPU maxed out, memory 18M~29M - Added cacheAsBitmap
FPS=1, CPU maxed out, memory 156~196M, memory keeps fluctuating
Disabled mouse + cacheAsBitmap
FPS=1, CPU maxed out, memory 156~196MDisabled mouse, no bitmap caching
fps=4, CPU maxed out, 21M~30MUsed the bitmap display object I wrote last year, but without memory reuse for the same object, so every time a new instance was created it would draw the content once from the source MC instance. Script execution was slow and memory usage was high. I’ll optimize a reusable version and test again shortly.
fps=13, CPU maxed out, memory 476MUsed the bitmap display object I wrote last year, with all characters placed within a single screen (scene is still 2880*2880)
fps=15, CPU maxed out, memory 476MUsed the bitmap display object I wrote last year, with all characters placed within a single screen (scene is still 2880*2880), and the character count reduced to 100
fps=23, CPU maxed out, memory 186~187M
Notes on 1 and 2: The official cacheAsBitmap consumes far too much memory, and it keeps creating bitmap caches while playing.
Comparing 3 and 4 against 1 and 2: Disabling the mouse makes little difference in a case like this, where nothing is listening and there are so many objects that it’s already extremely laggy.
Notes on 5 and 6: The smaller the region of the bitmap being modified, the higher the fps, but the memory consumed is the same (the whole bitmap).
Notes on 6 and 7: Direct bitmap operations aren’t slowed down by a large number of display objects on screen; efficiency depends on the number of pixel copy operations.
PS: Just switched to the 10.1 debug SA build — performance dropped by 1/4.
Added a single-frame Image with memory caching (clearing redundant bitmaps), and made the drawing area smaller (800*600)
fps=30, CPU around 42%, memory 8M~10MNew bitmap engine (with a memory resource pool added), 1500 MCs, area 800*600
fps=30, CPU around 42%, memory 10M~12M
Final result:
1500 MCs playing within the same screen, with a rated frame rate of 30.
Document Class :
package
{
import org.mousebomb.Math.MousebombMath;
import org.mousebomb.bmpdisplay.Animation;
import org.mousebomb.bmpdisplay.BmdObject;
import org.mousebomb.bmpdisplay.BmdResourcePool;
import org.mousebomb.bmpdisplay.BmpDisplayObject;
import org.mousebomb.bmpdisplay.Image;
import org.mousebomb.utils.SystemStatus;
import flash.display.Sprite;
import flash.display.StageAlign;
/**
* @author Mousebomb (mousebomb@gmail.com)
* @date 2010-6-21
*/
public class BmdEngineMC extends Sprite
{
/**
* BMD conversion test
*/
private var bmdStage : BmpDisplayObject;
private var bmdRoot : Image;
public function BmdEngineMC()
{
bmdRoot = new Image(800, 600);
bmdStage = new BmpDisplayObject(bmdRoot);
//Create the bitmap sequence
var src : MovieClip = new RoleD();
BmdResourcePool.getInstance().regResource(“roleD”, src);
addChild(bmdStage);
for (var i : int = 0;i < 1500;i++)
{
var bmdChild : BmdObject = BmdResourcePool.getInstance().getNewResource(“roleD”);
(bmdChild as Animation).play();
bmdChild.x = MousebombMath.randomFromRange(20, 600);
bmdChild.y = MousebombMath.randomFromRange(20, 550);
bmdRoot.addChild(bmdChild);
}
//Start rendering
bmdStage.renderEnterFrame = true;
this.stage.align = StageAlign.TOP_LEFT;
addChild(SystemStatus.getInstance());
}
}
}
Hahaha, the heavy character rendering the project needs is actually looking feasible.