📜 ⬆️ ⬇️

Why does Silverlight slow down?

Such a question “Why does Silverlight slow down?” Can be heard often enough, especially if you are developing solutions using Silverlight technology. Often you cannot win a tender, or persuade a customer to use Silverlight technology in your application, just because this popularity of thinking has already been fixed to him that all Silverlight applications are slowing down. Let's try to discuss this issue.

Example with SQL.RU



Recently, I began to look at messages in the WPF branch , Silverlight of the http://sql.ru forum, there I gave a recommendation about using MVVM frameworks (my position is known ), and ran into this question :

But do not tell me what the processor does for one of the links from this site, when I do not touch it? Assumptions what?

')
Retreat: In general, the impressions of the sql.ru forum so far are such that in any thread just a stupid flood begins about whether Silverlight is good or not.

So, about that application http://surfity.com/#/Images . Indeed, if there is something to type in the search, and then click on the Search button, then after the search itself you can find the following picture:

Capture

During idle time, the application continues to use the processor almost to its full capacity Is engaged in something in the background. It is clear that everything slows down a bit from such stubbornness of the application. I can not give an answer why in this case such a problem. But once I solved a similar bug, not created by me, but which any developer can allow.

An example of our team



The idea was simple. There was a graph that was drawn using Syncfusion controls (my favorite controls , this time the error was ours). The task was to display the line (such as the Target Line: the red line, which indicated where “well” turns into “bad”) on a regular Column graph. It looked like this:

Capture2

The Chart control, in this case, itself calculates the gradation it needs for the axes of coordinates, and depending on what maximum and minimum values ​​are present in the collection of values, it sets the maximum and minimum on the axes. In the picture it is approximately from 70 to 80. Next, the developer, for example, knows that Target Line is 78 - should see if there is such a value on the ordinate axis, and if there is, draw a line. Obviously, he needs some kind of event from the Chart control, such as “The graph is plotted and ready” so that he can determine where to draw the line, but there is no such event. One option is to subscribe to the LayoutUpdated event, which will be called after the schedule is drawn:

public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); Chart.LayoutUpdated += new EventHandler(Chart_LayoutUpdated); } void Chart_LayoutUpdated(object sender, EventArgs e) { // Draw line... } } 


And in the Chart_LayoutUpdated method, already add a line to the Chart control. It seems simple. After implementation, we check - everything works fine. We send the source code to TFS. See the problem? I think not many will be able to notice it immediately.

After long testing, the person who accepts the application says: “Everything is fine, but the application slows down as a whole, is there any way to make your Silverlight more smartly?”. It’s clear that you have a standard answer ready, like “This is a business application, not a notebook, it’s understandable that it slows down because it works.” But this is not in my case, I adore solving performance problems from the time of development in C ++, when making an application that drew drawings, and when an application compiled under Debug instead of 40 seconds began to draw drawings in 10 (in Release for a second), then I experienced a real thrill. Because I replied that I would try to see what could be done. First of all, I opened the application and began to work with it for a long time and hard, I did not see serious memory leaks, as I ate from 150 to 200 MB and continued to stay within this framework. But I noticed that if you do nothing, the application still on one of the screens continues to have 30-40% of the processor, although the rest 5%. It’s good that I had a Silverlight Spy application, with which I began to analyze our application and saw in the Event Monitor that on this very problematic screen, event LayoutUpdated is cyclically and constantly called. Then I got acquainted with this code and with this problem. Of course, after the graph was drawn and the LayoutUpdated event was raised, we add another element to the control, and of course the same event LayoutUpdated is called again and so on.

Tell me, how often do you test your applications for the fact that it can work for a long time? How often do you even open a simple Task Manager to see how your application behaves?

findings



Obviously, we, the developers, have made this platform partly inhibited. The Silverlight development team also has a lot of jambs for its part; you can only see how many memory leak was found in the core and base controls of Silverlight. But nevertheless, these memory leak are found, and the real Silverlight developers approach this very scrupulously, and as a result they produce excellent solutions.

So why do Silverlight applications slow down? Because this technology allows you to write web applications to any developers from beginners to gurus: a friendly development environment, a very simple development language, a huge amount of reference materials. Is it possible to take a novice developer and ask him to make an Html + JavaScript or Flash web application so that it works, it is also interesting / attractive? I’m talking about business applications, encyclopedia sites, not small toys and banners. I give this question with a 90% certainty the answer is no.

Therefore, in the future, if you focus on developing solutions for Silverlight, consider:



And let's create smaller braked applications. Winking smile

PS More than confident that there will be questions: “Show a normal application on Silverlight”. Immediately answer that I do not know these. In principle, our application behaves well, customers are satisfied, we solve problems with performance as they arise. I can not show it, because it is an intranet application.

Source: https://habr.com/ru/post/110398/


All Articles