miércoles, 9 de marzo de 2011

Performance decalogue for Silverlight

This guide has been done following my experience in Silverlight regarding the most useful gaps that I have had to use to make better Silverlight applications.
1.- Separate styles of a container with content having a container (without styles) composed by a layer with the styles and the content.

    Before
   
    <Container Background="XX" Border="XX">
        <Content/>
    </Container>

    After

    <Container>
        <Rectangle Background="XX" Border="XX"/>
        <Content/>
    </Container>

2.- Use CacheMode in animations with transformations -> There are a lot of guides to use. Mainly, not all elements can use the Cache and to activate it, you must configure the Silverlight host file to include:
    - EnableGPUAcceleration. You need to set to true to activate the hardware acceleration.
    - enableCacheVisualization. You must set it to false. But if you want to see visually the benefits of the cachemode, you have to set to true.
    - enableFrameRateCounter. If you set this property to true. You will see the frames used in the bottom-left corner of your browser.

3.- Making efficient animations. You will gain experience on this. Avoid either transformations with movements together opacity animations or transparent backgrounds of elements...

4.- No use innecessary or duplicated xmlns in your xaml files. This overload your page. Also, try to avoid to use the windowsless parameter (also for the host file of Silverlight). This parameter is used to enable the capatibility between html and Silverlight, nevertheless if you want to include html in your app, you will need it.

5.- For any list component use virtualization, recycling and ObservableCollections.   
   
6.- Use patterns: advanced MVVM (with validation, events, checkeable...) and Commanding. Avoid to use code behind events.

7.- Use less containers as be possible. This is more efficient and enable to achieve more flexibility to adapt your application to full size (StackPanels uses the minimal size available always).

8.- In Silverlight (overall for PRISM applications) is very common to attach events to listen something. Well.. if you attach to an event, remember detattach it when you don't need it. This avoids some memory leaks.

9.- Implements IDisponsable for your model. This enables that Garbage Collector identifies better the entities that already can remove.

10.- Use Integer instead of double for animations if you can.

However, have in mind to see always the used memory and familiarize yourself to use WinDbg tool to see some trouble with the entities that cannot be removed.

No hay comentarios:

Publicar un comentario