Jul 312013
 

Short story: In flash, bitmapData.lock() makes drawing faster by only updating the bitmap on screen when calling bitmapData.unlock() after done drawing, but once the bitmap is unlocked the whole bitmap is redrawn, instead of just the changed parts. If you only change small parts of a bitmap displayed on screen, and you do it often, this can result in a big performance hit.

I had been trying to optimize rendering of the canvas in Pyxel Edit without much luck, but then I tried Adobe Scout (awesome application btw!) that let me know that most of the time in the application was spent by the flash runtime rendering the display list. Apparently the whole canvas was re-drawn each time it changed just a bit. The odd thing was that the brush preview bitmap which is displayed on top was only rendered where it changed.

After some experimenting I found out that locking the bitmapdata of a bitmap object, which supposedly makes drawing faster, invalidates the whole bitmap and makes it get redrawn. Commenting out canvasBitmap.lock() immediately cut the displaylist rendering time by about 1/3 when drawing in the application.

To see what parts of the displaylist are redrawn one handy function is flash.profiler.showRedrawRegions(). It will draw rectangles around each redrawn region.

Jul 292013
 

This took me a while to figure out, in the end it was quite simple so I’m posting this to remind myself and possibly help someone else.

The “advanced telemetry” option in FlashDevelop doesn’t seem to do anything (as of FD 4.4.2). So you need to run a Python script on the compiled SWF. This can be done automatically after each build with a command in “Post-Build Command Line” in the FD project options.

1. Install Python (if you don’t already have it).
http://python.org

2. Download the script.
https://github.com/adamcath/telemetry-utils

3. Specify the post-build command.
Go to Project > Properties > Build and enter:

[path to python.exe] [path to script] [path to output swf]

In my case I have

"D:\Program Files (x86)\Python33\python.exe" $(ProjectDir)\add-opt-in.py $(OutputDir)\$(OutputName)

4. Done!
The script is now run on the file after each build.

More info: http://www.adobe.com/devnet/scout/articles/adobe-scout-getting-started.html