Mar 12

Looking to squeeze every bit of performance out of your Silverlight game? Be careful about setting and getting dependency property values (like Visibility, Canvas.Left, etc). First of all, there is overhead and code that runs behind the scenes when doing this, so it’s a good idea to wrap these properties and keep a local copy and return this one when getting a value and comparing against it before setting a value. This is just some common sense optimization.

There is, however, a potentially more important reason to compare to a local value before setting the property. Even if you set a dependency property to the same value it had before, this is treated as a change and can cause Silverlight to have to re-render the element. This is especially important when using BitmapCache to take advantage of GPU rendering.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

2 Responses to “Setting dependency properties and the effect on performance”

  1. Ray Says:

    Wrote a post on a class to facilitate caching dependency property values in line with your other Space Rocks series: http://blog.invalidoperation.com/2010/03/14/Cachi...

    Cheers

  2. billreiss Says:

    Ray, this is cool I love when people take something I do and bring it to the next level. Thanks!

Leave a Reply

preload preload preload