HTML5 Canvas performance depends on display objects, canvas dimensions, update logic and drawing cost. Testing an HTML5 Canvas document from Animate can also open a browser and run published code. Compare templates, assets and runtime configuration when deployment behaves differently.
The export is an executable display tree
Publishing an HTML5 Canvas document generates JavaScript display objects and timeline code. Animated symbols may use createjs.MovieClip; shapes and containers have other types. Inspect the generated constructors:
Stage
└─ Container (a symbol instance)
├─ Shape (vector artwork)
├─ Bitmap (image / sprite sheet region)
├─ Text
└─ MovieClip (nested symbol with its own timeline)
Graphic synchronisation can use MovieClip.SYNCHED or SINGLE_FRAME, without flattening into the parent. Inspect generated objects, modes and asset reuse before comparing object counts.
Default Stage clearing and redraw
Canvas 2D retains no scene-object tree; CreateJS maintains its own display list. A Stage defaults to autoClear=true, clearing and redrawing visible content on update. Disabling clearing, caching or using drawRect changes this path.
A Bitmap usually calls drawImage, with cost also affected by scaling, blending and uploads. A Shape executes Graphics instructions. Encoded paths are normally decoded during construction, rather than reparsed on each draw. Caching can reduce repeated drawing of static complex vectors.
Which explains a counter-intuitive observation: a complex vector background sitting perfectly still can cost more than a bitmap character running across it. It does not move, but it is still re-rasterised on every frame.
Cache reuse and update cost
The remedy is caching. Calling cache() renders a display object and its subtree into an offscreen canvas; from then on each frame only needs to drawImage that offscreen bitmap.
shape.cache(x, y, width, height, scale);
// after the internal content changes, refresh explicitly:
shape.updateCache();
Check three parameters when configuring the cache:
- Cache bounds: cover local artwork and strokes, and check whether the version already expands filter bounds.
- Cache resolution: select scale from final enlargement and pixel density, comparing memory and quality.
- Cache updates: refresh when internal content changes and measure whether caching helps.
Try caching complex objects with static interiors. Updating each frame adds offscreen rendering and composition, but reuse, filters or backend behaviour can still justify it. Measure frame time and memory in the same scene.
Canvas 2D filters and caches
The ordinary EaselJS 1.0.0 Canvas 2D filter path processes cached pixels, so establish or update a cache after setting filters. Check StageGL and other backends against their supported filter and cache mechanisms:
obj.filters = [new createjs.BlurFilter(8, 8, 1)];
obj.cache(0, 0, w, h); // without this line the filter is invisible
The base cache rectangle should cover artwork and strokes. EaselJS 1.0.0 BitmapCache expands it using filter bounds. Check custom filters and other versions to avoid clipping or duplicating that expansion.
There are two frame rates and they can disagree
The Animate document carries a frame rate setting, and the CreateJS Ticker carries another. The published template normally initialises the Ticker from the document rate, but once the template has been hand-edited, or other code on the page touches the Ticker, the two can diverge — and the animation runs uniformly fast or slow.
createjs.Ticker.timingMode = createjs.Ticker.RAF;
createjs.Ticker.framerate = 24;
EaselJS Ticker.RAF follows requestAnimationFrame and ignores the target framerate; setting 24 above does not throttle RAF to 24 Hz. RAF_SYNCHED targets an approximate tick rate. Time-based MovieClip advancement also depends on its own framerate and tick delta. Configure logical time and render scheduling separately.
Measure instead of guessing
Use the browser performance panel to locate the bottleneck:
- Profiling: inspect call stacks, Canvas calls, drawing and GPU evidence together; Scripting can include drawing-command cost.
- Hide a layer and repeat under the same conditions. A frame-time drop supports its contribution to cost.
- Compare cached and uncached frame time, memory and quality in the same scene.
- Canvas pixels: scaling both dimensions by a DPI factor of 2–3 multiplies pixel area by 4–9. Check actual backing-store dimensions.
When to abandon vectors entirely
Compare sprite playback with vector drawing. Bitmaps reduce path execution but add textures and frame assets; bytes, memory and speed depend on packing, reuse, resolution and backend. Filters or shaders can recolour bitmaps, though they do not expose individual vector paths.
Choose vectors, caches or sprite sequences by comparing scale range, recolouring needs, reuse, download size and frame time for each element. Verify mixed approaches in the same scene.
This article covers runtime behaviour after export; for how symbol type governs timeline evaluation while authoring, see the Animate timeline and symbol model. The full reading order for the series is on the 2D Animation Principles page.