Wednesday, December 10, 2008

Silverlight 2 Performance Best Practices

Here is some more 'content' summary info from my Architectural Best Practices presentation at DevTeach.

As to performance best practices… use the following as a good starting place:

· Don’t stretch things including Images, videos, or paths. Stretching things is going to cause more processing. Create assets at the size that they will be used and life will be much easier.


· Don’t use ECMA Script or the Anti-Pattern Silverlight 1.0.


· Don’t use windowless mode.


· Remove event handlers and set them to null before removing the element from the visual tree.


· Set MediaElement sources to null before removing them from the tree.


· Don’t use opacity if you just need to make things disappear, instead use the visibility property.


· Do use ‘IsHitTest’ and set it to false when doing drag and drop do hit testing only happens on the elements that are drag targets. This also allows you to keep visual elements from interfering with role over related events such as Mouse Enter and Mouse Exit events.


· Don’t have 1000 thousand elements in the same Visual Tree…


· If something is going to take a while tell the user or show the user that we are waiting.


· Don’t use ‘findName’ if you don’t have too as this causes a walk through the visual tree.


At least following these rules for Architecture and Performance your application won’t fall on its face.