Performance. Practical Recommendations

Even the very best performing component could be hindered by incorrect use. Below we offer practical tips about what ought to be used or prevented in application programming. Following a tips below it is possible to create applications with the same effectiveness as this demo software. We provide source codes because of this example showing how easy it really is.

It really is supposed that programmers know general concepts of application design. However, we shall offer some useful links for better knowledge of .Net environment and equipment for composing managed code: Writing Faster Managed Code: KNOW VERY WELL WHAT Things Cost

It’s important to focus on grid characteristics in various working modes, to judge data volume to end up being displayed and to look for a relevant chart for better knowledge of grid use.

Have only 1 message loop per software. Don’t create grids in various threads.

Why don’t we assume that the pc resources aren’t limitless. Theoretically the utmost performance can be acquired if the amount of threads equals to the amount of processor chip cores. While a whole lot of threads are creating, they aren’t employed in parallel. In cases like this cores allocate period slices to threads predicated on their concern and regularly perform context switches (context switch is fairly expansive operation). Note, optimum time slice is approximately 10-15 msec.

We have also remember that each control paints its articles in the GDI/GDI+ device (via the Images object). While painting in one thread all others await GDI device to execute painting in its convert. Therefore if we begin many message loops – it generally does not imply that we accelerate the application form. In other phrases the application losses period on context switches and on drawing in GDI gadget.

From our viewpoint the application must have only 1 message pump. Home windows has extra mechanisms to optimize articles drawing and we aren’t sure that they function in case there is multithreaded environment. Of training course, business logic could work in any thread, however the graphical thread ought to be just one in the application form.

Make use of MethodInvoker to synchronize threads.

In multi-threaded applications every single call ought to be synchronized with the primary thread containing windows message loop. Both Control.Invoke and Control.BeginInvoke strategies might accept different delegate types and their parameters. Nevertheless, this causes a significant performance issue because they contact Delegate.DynamicInvoke(params object[] args), which uses low-performance reflection. Simultaneously, for some delegates such as for example EventHandler, MethodInvoker and WaitCallback the code is named directly. In enough time of code execution the delegate can be checked for owned by among the above types with specified quantity of parameters, and if it generally does not – DynamicInvoke() is named.

Make use of objects of arbitrary classes rather than collections of values of string[] type, etc. It really is more convenient and items of arbitrary classes eat less memory than string selections.

Don’t format values straight in data items, i.e. if an object real estate is to return day, this field should come back DateTime object type rather than string type. Make use of data formatting if required. If properties come back strings, they could be compared incorrectly during data sorting. Besides, evaluating two strings requires even more CPU resources than evaluating two DateTime objects.

This working principle may be the same for all grids of most vendors. The main concern can be that PropertyDescriptor.GetValue() technique uses reflection. NetGrid comes with an optimization that allows it to get notifications from INotifyPropertyChanged/IBindingList without phoning data object getters. Ideals are required only during painting and limited to noticeable cells. If the grid includes a great deal of rows, many of them are invisible which approach considerably saves CPU assets. It is worth taking into consideration in application development. For example, let’s review membership to Grid.RowUpdated event:

When updating data instantly in applications, the grid shops highlighting information for every updated cell. This default behavior causes serious usage of memory resources furthermore to CPU resource usage because of processing large level of information. Because so many updates can occur beyond your visible region, the programmer can save CPU assets utilizing the new property.

When this optimization can be used, vertical scrolling may provide rows without cell highlighting info to the visible area and an individual won’t see cell highlights which were made just before rows reach visible section of the grid. This concerns just highlighting information, while text message and other cell content material will display properly. The programmer should determine whether to make use of such optimization or not really.

Be careful about creating short-term objects as it might result in memory space pressure and make garbage collector gather unused objects more often. Please note that whenever garbage is gathered, all program threads are temporarily halted.

Avoid finalizers in items unless necessary.

We hope these simple recommendations can help you create effective and high-performing applications.

Related Posts