Silverlight performance optimization Summary-Original Author jossef Goldberg

Source: Internet
Author: User

 

As a brand-new architecture of Microsoft for rich network applications, Silverlight has a strong impact on developers and users, and countless developers are fascinated by its outstanding performance, at the same time, Microsoft's designers are constantly improving and enriching it. At the same time, the Silverlight team is also actively building Silverlight 5. Its initial version has been demonstrated at http://channel9.msdn.com/series/silverlight-firestarter, so you can embrace the future of silverlight. After learning the performance optimization event, I made a summary of the introduction and hope to give you a brief introduction.

Performance optimization is a step-by-step iteration process in which you need to do the following:

1. Identify the key steps that affect performance;

2. Set clear objectives;

3. Perform regular and early performance tests;

4. monitor new features;

5. perform the test at the final deployment stage.

I. sivlerlight optimization at startup:

Reduce the xap package downloads; Remove unnecessary XAML tags as much as possible to reduce resolution time; use delayed loading to reduce interaction with disk Io and use welcome pages to improve the user experience during loading.

Here, jossef Goldberg also provides the key to dynamic xap package download.CodeExample [DataGrid Control Optimization]:

Because the DataGrid control library is not provided in the Silverlight core libraryProgramIf this control is used, the corresponding SDK control library of about KB is loaded. Therefore, if your application does not use the DataGrid control from the very beginning, then we can use the delayed download and dynamic loading methods.

Detailed steps and code

Ii. optimization performance during running:

1. Reduce page re-painting;

A: reduce page updates.

Silverlight only redraws dirty pages, so we can reduce the use of large-space animations; disable the hidden animations in the page and pay attention to the default animation behavior of the control.

B: directly update the page

This can be achieved by setting two page parameters of the Silverlight object, namely, enableredrawregions and enableframeratecounter:

The corresponding settings are as follows:

<Param name ="Enableredrawregions"Value =" true "/>

<Param name ="Enableframeratecounter"Value =" true "/>

2. Use effects with caution;

Since the use of cool effects can enhance the expressiveness of the program, many designers like it, but using effects will bring performance problems to our applications, because effects are presented by CPU computing, you cannot obtain the benefits of GPU operations, so use them as little as possible. If you want to use effects, be sure not to modify the attributes of effects, or use them on animation components and apply effects to subnodes.

3. GPU Acceleration;

Because Silverlight can use bitmap cache, cached bitmaps are used in GPU memory, so bitmap cache can be accelerated through GPU. GPU acceleration can be used for the following elements: render transforms (transformation); opacity (transparency); rectangular clip (rectangular cut); projects (Perspective ). others such as effects, opacity mask (transparent mask), non-rectangular clips (non-rectangular cut) can only be presented by the CPU.

GPU acceleration steps are as follows:

1) set to allow GPU acceleration at the plug-in Level

<Param name = "enablegpuacceleration" value = "true"/>

2) allow bitmap caching at the Element Level

<Stackpanel cachemode = "bitmapcache"… >

3) Optimization: controls the scale or quantity of cached bitmaps (the number is equivalent to the memory, especially for scaling scenarios)

<Bitmapcache renderatscale = "2".../>

When Will bitmapcache be used? In general, the expensive operations that present many elements, such as: GPU can animation their attributes and consider using it when users can obviously feel the performance impact. Do not use bitmapcache for visual elements of large formats, because software is used for simulation when the GPU cache is insufficient, which is counterproductive. If the sub-elements are also used by animators, do not use bitmapcache, because when cache is used, all child elements are added to the cache.

4. Simplified Xmal markup (reducing the complexity of the visual tree );

1) The smaller the visible tree, the faster it will be: attributes, arrangement, binding, input, and style will increase the overhead. At the same time, the small tree will make the Event Routing faster and the memory usage is less, in programming, it is also easy to measure the number of elements.

2) Beware of template expansion: the designer's template may be an explosive growth of your visual tree. Because the user control will try to parse every instance, this increases the overhead. This is because we should use templates instead of user controls.

3) useless subtree processing: Remove unnecessary child numbers for a long time and replace visibility = "Collapsed" with opacity = "0" because the former will not allocate instances.

5. Avoid UI thread blocking;

The UI thread of the Silverlight shared browser, including animation, arrangement, events, user input, and app code. Frame Rasterization, media decoding, and GPU operations do not use the UI thread. And only the UI thread can enter the XAML object.

Time-consuming operations may affect page rendering such as animation, input, and arrangement. We can use the following two methods to avoid these time-consuming operations blocking your UI rendering:

1) Put these long tasks into independent code blocks, and then use dispatcher. begininvoke () for asynchronous calls;

2) You can also use the backgroundworker multi-threaded processing mechanism because it has built-in reporting progress and cancelling functions.

As a brand-new architecture of Microsoft for rich network applications, Silverlight has a strong impact on developers and users, and countless developers are fascinated by its outstanding performance, at the same time, Microsoft's designers are constantly improving and enriching it. At the same time, the Silverlight team is also actively building Silverlight 5. Its initial version has been demonstrated at http://channel9.msdn.com/series/silverlight-firestarter, so you can embrace the future of silverlight. After learning the performance optimization event, I made a summary of the introduction and hope to give you a brief introduction.

Performance optimization is a step-by-step iteration process in which you need to do the following:

1. Identify the key steps that affect performance;

2. Set clear objectives;

3. Perform regular and early performance tests;

4. monitor new features;

5. perform the test at the final deployment stage.

I. sivlerlight optimization at startup:

Reduce the xap package downloads; Remove unnecessary XAML tags as much as possible to reduce resolution time; use delayed loading to reduce interaction with disk Io and use welcome pages to improve the user experience during loading.

Here, jossef Goldberg also provides a key code example for dynamically downloading the xap package [DataGrid Control Optimization]:

Because the DataGrid control library is not provided in the Silverlight core library, if this control is used in our program, the corresponding SDK control library of about 144kb will be loaded, therefore, if your application does not use the DataGrid control from the very beginning, we can use the delayed download and dynamic loading methods.

Detailed steps and code

Ii. optimization performance during running:

1. Reduce page re-painting;

A: reduce page updates.

Silverlight only redraws dirty pages, so we can reduce the use of large-space animations; disable the hidden animations in the page and pay attention to the default animation behavior of the control.

B: directly update the page

This can be achieved by setting two page parameters of the Silverlight object, namely, enableredrawregions and enableframeratecounter:

The corresponding settings are as follows:

<Param name ="Enableredrawregions"Value =" true "/>

<Param name ="Enableframeratecounter"Value =" true "/>

2. Use effects with caution;

Since the use of cool effects can enhance the expressiveness of the program, many designers like it, but using effects will bring performance problems to our applications, because effects are presented by CPU computing, you cannot obtain the benefits of GPU operations, so use them as little as possible. If you want to use effects, be sure not to modify the attributes of effects, or use them on animation components and apply effects to subnodes.

3. GPU Acceleration;

Because Silverlight can use bitmap cache, cached bitmaps are used in GPU memory, so bitmap cache can be accelerated through GPU. GPU acceleration can be used for the following elements: render transforms (transformation); opacity (transparency); rectangular clip (rectangular cut); projects (Perspective ). others such as effects, opacity mask (transparent mask), non-rectangular clips (non-rectangular cut) can only be presented by the CPU.

GPU acceleration steps are as follows:

1) set to allow GPU acceleration at the plug-in Level

<Param name = "enablegpuacceleration" value = "true"/>

2) allow bitmap caching at the Element Level

<Stackpanel cachemode = "bitmapcache"… >

3) Optimization: controls the scale or quantity of cached bitmaps (the number is equivalent to the memory, especially for scaling scenarios)

<Bitmapcache renderatscale = "2".../>

When Will bitmapcache be used? In general, the expensive operations that present many elements, such as: GPU can animation their attributes and consider using it when users can obviously feel the performance impact. Do not use bitmapcache for visual elements of large formats, because software is used for simulation when the GPU cache is insufficient, which is counterproductive. If the sub-elements are also used by animators, do not use bitmapcache, because when cache is used, all child elements are added to the cache.

4. Simplified Xmal markup (reducing the complexity of the visual tree );

1) The smaller the visible tree, the faster it will be: attributes, arrangement, binding, input, and style will increase the overhead. At the same time, the small tree will make the Event Routing faster and the memory usage is less, in programming, it is also easy to measure the number of elements.

2) Beware of template expansion: the designer's template may be an explosive growth of your visual tree. Because the user control will try to parse every instance, this increases the overhead. This is because we should use templates instead of user controls.

3) useless subtree processing: Remove unnecessary child numbers for a long time and replace visibility = "Collapsed" with opacity = "0" because the former will not allocate instances.

5. Avoid UI thread blocking;

The UI thread of the Silverlight shared browser, including animation, arrangement, events, user input, and app code. Frame Rasterization, media decoding, and GPU operations do not use the UI thread. And only the UI thread can enter the XAML object.

Time-consuming operations may affect page rendering such as animation, input, and arrangement. We can use the following two methods to avoid these time-consuming operations blocking your UI rendering:

1) Put these long tasks into independent code blocks, and then use dispatcher. begininvoke () for asynchronous calls;

2) You can also use the backgroundworker multi-threaded processing mechanism because it has built-in reporting progress and cancelling functions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.