Content Creation Memory and Performance Considerations

When developing Flash content, there are a number of considerations and optimizations that should be followed and implemented in order to get the best performance.

Draw Primitives

Draw primitives (DPs) are mesh objects created by Scaleform to render Flash elements to the display, such a shape . On platforms supporting batched (or instanced) rendering, Scaleform attempts to group shapes on the same and adjacent layers with the compatible properties into a single DP. Each DP is rendered independently, incurring a performance cost. In general, Display performance will tend to decrease linearly as more DPs are introduced into the scene; therefore it is a good practice to keep the DP count as low as possible. The number of DPs can be determined via the Scaleform Player HUD by pressing the (F2) key. This screen displays triangle counts, DPs, memory use and other optimization information.

The following are a few facts to help keep draw primitive count low:

  1. DPs can only contain items which have the same properties (excluding shape with different solid colors). For example, items with different textures or blending modes can never be combined in a DP.
  2. Overlapping objects on different layers cannot be combined into a DP, even if they have the same properties.
  3. Gradient fills can increase the number of DPs if several of them are used in a shape at the same time.
  4. Vector graphics with solid color fills and no strokes are very cheap.
  5. Empty movie clips do not require a DP; however, a movie clip with objects in it will require the amount of DPs dictated by those objects.

The batching and/or instancing groups can be visualized in the Scaleform Player by enabling the option in AMP, or by pressing (Ctrl+J). In this mode, items with the exact same color are rendered as a single DP.

Movie Clips

  1. Rather than hiding movie clips, it is best to delete them completely from the timeline when not in use, otherwise they may take up processing time during Advance.
  2. Avoid excessive nesting of movie clips, as this will affect performance.
  3. If it is necessary to hide a movie clip then use _visible=false rather than _alpha=0 (in AS2) and visible=false rather than alpha=0 (in AS3). Make sure you have stopped the animation in hidden movie clips by calling the "stop()" function. Otherwise, invisible animation will still take place and affect performance.

Artwork

Bitmaps vs. Vector graphics

Flash content can be created with vector art as well as images and Scaleform can seamlessly render both vector and bitmap graphics. However, each type has its advantages and disadvantages. The decision to use vector or bitmap graphics is not always clear, and often depends on several factors. This section discusses some of the differences between vector and bitmap graphics to help make content authoring decisions.

Vector graphics maintain their smooth shapes when scaled in size, unlike bitmaps images that can appear box-like, or pixelated, when scaled. But unlike bitmaps, vector graphics require more processing power to generate. Although simple solid-color shapes will usually be as fast as bitmaps, complex vector graphics with many triangles, shapes and fills can be expensive to render. Consequently, heavy use of vector shapes can sometimes reduce overall application performance. Bitmap graphics can be a better choice for some applications because they don't require as much processing time to render as vectors, however, bitmap graphics significantly increase the amount of memory required, compared to vector graphics.

Vector Graphics

Vectors graphics are more compact than other image formats because vectors define the math (points, curves, and fills) required to render the image at runtime rather than the raw graphic (pixel) data of a bitmap. However, converting the vector data to the final image is time consuming and must be done whenever there is significant change in appearance or scale of a graphic. If the movie clip contains complex shape outlines that change every frame, animations may run slowly.

The following are several guidelines to help render vector graphics efficiently:

Bitmaps

The first step in creating optimized and streamlined animations or graphics is to outline and plan your project before its creation. Specify a target for the file size, memory usage and length of the animations that you want to create, and test throughout the development process to ensure that you are on track.

In addition to draw primitives described earlier, a significant factor that affects rendering performance is the total surface area drawn. Every time a visible shape or bitmap is placed on the Stage, it needs to be rendered even if it is hidden by other overlapping shapes, consuming video card fill-rate. Although today’s video cards are an order of magnitude faster than software Flash, large overlapping alpha-blended objects on screen can still greatly reduce performance, especially on lower-end and older hardware. For this reason it is important to flatten overlapping shapes and bitmaps, and explicitly hide obscured objects.

When hiding objects, it is best to set the _visible (in AS2) or visible (in AS3) property of a movie clip instance to false instead of changing the _alpha (in AS2) or alpha (in AS3) level to 0 in a SWF file. Although Scaleform will not draw objects with _alpha/alpha value of 0, their children may still incur CPU processing cost due to animation and ActionScript. If the instance visibility is set to false, then there is potential for CPU cycles and memory savings, which can give your SWF files smoother animations and provide better overall performance for your application. Instead of unloading and possibly reloading assets, set the _visible/visible property to false, which is much less processor-intensive. The following are several guidelines to help render bitmap graphics efficiently:

Animation

When adding animation to an application, consider the frame rate of the FLA file. It can affect the performance of the final SWF file. Setting a frame rate too high can lead to performance problems, especially when many assets are used or AS is used to create animations that are ticked with the document’s frame rate.

However, the frame rate setting also affects how smoothly the animation plays. For example, an animation set to 12 frames per second (FPS) plays 12 frames of the timeline each second. If the document's frame rate is set to 24 FPS, the animation appears to animate more smoothly than if it is set to 12 FPS. However, an animation at 24 FPS also plays twice as fast as it would at 12 FPS, so the total duration (in seconds) would be half the duration. Therefore, in order to make a 5-second animation using a higher frame rate, additional frames are required to fill those five seconds than at a lower frame rate, which raises the total file size.

Note: When using an onEnterFrame (in AS2) or Event.ENTER_FRAME (in AS3) event handler to create scripted animations, the animation runs at the document's frame rate, similar to creating a motion tween on the timeline. An alternative to the onEnterFrame/Event.ENTER_FRAME event handler is setInterval. Instead of depending on frame rate, functions are called at a specified interval of milliseconds. Like onEnterFrame/EVENT.ENTER_FRAME, the more frequently setInterval is used to call a function, the more resource intensive the animation will be.

Use the lowest possible frame rate that renders a smooth animation at runtime. This will help reduce the performance hit on the processor. Try not to use a frame rate that's more than 30 to 40 FPS; high frame rates beyond this point increase CPU cost and do not greatly improve the animation smoothness. In most cases, Flash UI can be safely set to half the target frame rate of the underlying game.

The following are several guidelines to help design and create efficient animations:

Text and Fonts