Bitmap Caching in Silverlight 3

In my opinion, one of the coolest new features in Silverlight 3 is Cached Composition.  Cached Composition is a performance enhancement feature that will allow visual elements to be cached as bitmaps after the first render.  After caching occurs, the application can effectively bypass the render phase for the cached visual elements and simply display the cached elements instead.

This is a huge plus for scenarios with scrolling objects!  Before Cached Composition, Silverlight would re-render the object for each frame, even if the object itself never changed.  With Cached Composition enabled, the object is cached and Silverlight can render the object even faster.

Composition Caching

Composition Caching is an opt-in feature.  In other words, you must first enable composition caching at the plug-in level by setting a parameter like so:

<param name="EnableGPUAcceleration" value="true" />

After enabling GPU acceleration, you can then specify at the elements you wish to cache.  Specifying the CacheMode is a simple matter of setting a property:

<Grid CacheMode="BitmapCache" …

Here are a few notes about BitmapCaching:

  • BitmapCache is the only cache-mode that is supported.
  • The Caching is applied to the element and all of it’s child elements.
  • BitmapCaching should be used in scenarios where you are blending, transforming (translating, stretching, rotating).
  • Misuse of the CacheMode feature can hurt performance, so you need to really think through what you are doing.  If your visual tree is interleaving cached and un-cached elements, you are effectively causing multiple rendering surfaces to get created behind the scenes.  The un-cached surfaces are rendered in software and the cached surfaces are rendered in hardware.  Your performance will be best if you can minimize the total number of rendering surfaces and get the hardware to do work where it can.
  • You can determine which elements are being cached by adding the EnableCacheVisualization parameter to your Silverlight plugin declaration.     <param name="EnableCacheVisualization" value="true" />
  • As far as I can tell, GPU acceleration does not occur on Macs when the Silverlight application is not in full-screen mode.  This is apparently a limitation of the Safari plug-in model.
Comments have been closed on this topic.