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.
March 14th, 2010 at 10:55 PM
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
March 14th, 2010 at 11:02 PM
Ray, this is cool I love when people take something I do and bring it to the next level. Thanks!