Looking for advice on FPS drop when using display.GraphicsPath commands for a simple paint program

Hello, I’m a new haxe/openfl programmer and am looking for some guidance on resolving a significant FPS drop. I created a simple paint program where the user clicks on a palette to change the paint color, then moves the mouse to paint:

  • My “Canvas” class extends Sprite.
  • On each ENTER_FRAME event, if the mouse has moved more than 5 pixels, graphics.lineTo( ) is called to draw a line segment to the new mouse location.

For the initial 100 or so lines, the frame rate dips to ~50 FPS when each line is drawn, then rises back up to 60 FPS when idle. Performance feels fine. The dip in the frame rate becomes greater as each new line is added. When the number of lines exceeds around 300, the frame rate drops below 10 FPS while drawing, then rises back to 60 FPS when idle. Performance is noticeably sluggish.

Can anyone make a suggestion about what I should try or look into? This is my first haxe program. Any help would be welcome.


On native platforms, for quality, the graphics API uses software rendering. As a result, each change will result in a somewhat longer software render pass, then the performance returns to the original speed after the software render pass is done, and it can keep the cached result.

As a workaround for the moment, perhaps there is a way you can perform caching of old drawing content?

For example:

var sprite = new Sprite ();
sprite.graphics.beginFill (0xFF0000);
sprite.graphics.drawRect (0, 0, 100, 100);

var bitmapData = new BitmapData (sprite.width, sprite.height);
bitmapData.draw (sprite);
var bitmap = new Bitmap (bitmapData);
addChild (bitmap);

In this example, content is drawn using sprite.graphics, and the result is cached to a bitmap.

It might be possible to have a Sprite you use for new content the user is drawing, and periodically (once a second? once every X number of operations?) you draw the work onto the BitmapData object, and clear the Sprite. I believe this would look the same, but you can consider how changes will only result in a few things being redrawn