<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dapfor.Net Grid Blog &#187; Performance</title>
	<atom:link href="http://www.blog.dapfor.com/performance/feed" rel="self" type="application/rss+xml" />
	<link>http://www.blog.dapfor.com</link>
	<description>.Net Grid and MFC Grid</description>
	<lastBuildDate>Fri, 09 Sep 2016 05:40:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>.NetGrid v2.10.3 has been released</title>
		<link>http://www.blog.dapfor.com/netgrid-v2-10-3-has-been-released</link>
		<comments>http://www.blog.dapfor.com/netgrid-v2-10-3-has-been-released#comments</comments>
		<pubDate>Fri, 09 Sep 2016 05:40:24 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[bug fixing]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Windows 10]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=303</guid>
		<description><![CDATA[A new version contains support for Windows 10, as well as bug fixes. The following improvements have been made: [NEW] .Net Grid/Suite is now compatible with Windows 10 The following bugs have been fixed: [BUG] Fixed a bug where in some rare cases .Net Grid could cause an exception during the redrawing data. [BUG] Fixed bug [...]]]></description>
			<content:encoded><![CDATA[<p>A new version contains support for Windows 10, as well as bug fixes.</p>
<div>The following improvements have been made:</div>
<ul>
<li>[NEW] .Net Grid/Suite is now compatible with Windows 10</li>
</ul>
<p>The following bugs have been fixed:</p>
<ul>
<li>[BUG] Fixed a bug where in some rare cases .Net Grid could cause an exception during the redrawing data.</li>
<li>[BUG] Fixed bug in <a href="http://doc.dapfor.com/net-suite/html/T_Dapfor_Net_Formats_DecimalFormat.htm">DecimalFormat</a> when .Net Grid incorrectly displayed data equal to zero.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/netgrid-v2-10-3-has-been-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wpf GridControl v4.0.0 has been released</title>
		<link>http://www.blog.dapfor.com/wpf-gridcontrol-v4-0-0-has-been-released</link>
		<comments>http://www.blog.dapfor.com/wpf-gridcontrol-v4-0-0-has-been-released#comments</comments>
		<pubDate>Mon, 25 Apr 2016 15:49:54 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[Data binding]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[thread safety]]></category>
		<category><![CDATA[cell blinking]]></category>
		<category><![CDATA[datatemplate]]></category>
		<category><![CDATA[GridControl]]></category>
		<category><![CDATA[styles]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[Wpf]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=261</guid>
		<description><![CDATA[During development, we discovered that although WPF technology has many advantages, it utilizes a lot of computer resources. Therefore, creating a high quality and high performance product requires significant developer experience and deep understanding of technology. Out developers have invested of lot of effort in GridControl and as the result it has all the advantages of its [...]]]></description>
			<content:encoded><![CDATA[<p>During development, we discovered that although WPF technology has many advantages, it utilizes a lot of computer resources. Therefore, creating a high quality and high performance product requires significant developer experience and deep understanding of technology. Out developers have invested of lot of effort in <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol">GridControl</a> and as the result it has all the advantages of its predecessor, <a href="http://www.dapfor.com/en/net-suite/net-grid">.Net Grid</a>, including high performance.<br />
&nbsp;</p>
<div><img class="aligncenter" src="http://doc.dapfor.com/wpf-suite/media/features_6.png" alt="Wpf GridControl" width="685" height="411" align="center" /></div>
<p>&nbsp;</p>
<div>We have preserved <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol/features/thread-safety">thread safety</a> of dynamic data in non-graphical thread enabling implementation of a thread-safe <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol/tutorial/tutorial-part3">event-driven model</a>. GridControl is the only graphical component that is able receive notifications (price changes or any other information) from the business model and from any thread.However, we mainly focused on ease of use, intuitiveness and minimization of code volume in final application. As the result, the grid supports <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol/tutorial/tutorial-part1">any data types</a>, creating any kind of <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol/features/binding-row">hierarchy</a>, <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol/tutorial/tutorial-part9">sorting</a>, <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol/tutorial/tutorial-part11">filtering</a> and <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol/tutorial/tutorial-part10">grouping</a>. All of these features require just a few code lines.</p>
<p>The Wpf GridControl is the only component providing real-time services of simultaneous data grouping, sorting and filtering. This problem is very complex for developers to solve. As example, imagine blotter displaying several dozens shares sorted by constantly changing percentage of price fluctuation. In addition to that, users can apply filters to display only shares with the highest price change. A lot of complex and inefficient code is required to implement this functionality in other grid. Our GridControl has integrated data sorting, filtering and grouping services that continuously display rows in correct order even when they change all the time.<br />
&nbsp;
</p></div>
<div><img class="aligncenter" src="http://doc.dapfor.com/wpf-suite/media/features.png" alt="Wpf GridControl features" width="675" height="275" align="center" /></div>
<div>
&nbsp;<br />
We have also moved the feature of short-term <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol/tutorial/tutorial-part12">cell blinking</a> from .Net Grid to the new product. Users can set highlighting color and duration for individual cells using the provided callbacks.</p>
<p>We haven&#8217;t forgotten about specific advantages of WPF technology and now our application can display any controls in grid cells with <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol/tutorial/tutorial-part5">DataTemplate and DataTemplateSelector</a>. You can also alter grid appearance easily using <a href="http://www.dapfor.com/en/wpf-suite/gridcontrol/tutorial/tutorial-part6">preset or custom styles</a>.
</div>
<p>&nbsp;</p>
<div>
<img class="aligncenter" src="http://doc.dapfor.com/wpf-suite/media/features_5.png" alt="Wpf GridControl data templates" />
</div>
<p>&nbsp;</p>
<div>
We hope that you will be surprised by outstanding quality of our work and really appreciate it.</p>
<p>We believe that our products will deserve your attention and that with our help you will develop excellent high-performance user-friendly applications.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/wpf-gridcontrol-v4-0-0-has-been-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NetGrid v2.10.1 has been released</title>
		<link>http://www.blog.dapfor.com/netgrid-v2-10-1-has-been-released</link>
		<comments>http://www.blog.dapfor.com/netgrid-v2-10-1-has-been-released#comments</comments>
		<pubDate>Fri, 25 Mar 2016 14:53:30 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[64 bit platform]]></category>
		<category><![CDATA[bug fixing]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=252</guid>
		<description><![CDATA[A new version contains improved support for 64-bit platforms, as well as bug fixes. The following improvements have been made: [NEW] Significantly increased .NetGrid initialization speed at runtime. This will reduce the time to start an application that uses a large number of grids. [NEW] Improved support for 64-bit platforms. [NEW] .NetGrid/.NetSuite are now correctly installed in [...]]]></description>
			<content:encoded><![CDATA[<p>A new version contains improved support for 64-bit platforms, as well as bug fixes.</p>
<div>The following improvements have been made:</div>
<div></div>
<ul>
<li>[NEW] Significantly increased .NetGrid initialization speed at runtime. This will reduce the time to start an application that uses a large number of grids.</li>
<li>[NEW] Improved support for 64-bit platforms.</li>
<li>[NEW] .NetGrid/.NetSuite are now correctly installed in Windows 10.</li>
<li>[NEW] Changed installation location for 64-bit systems from &#8216;C:\Program Files (x86)\Dapfor&#8217; to &#8216;C:\Program Files\Dapfor&#8217;.</li>
<li>[NEW] Improved support for .NetGrid in design-time.</li>
</ul>
<p>The following bugs have been fixed:</p>
<ul>
<li>[BUG] Fixed an issue where .NetGrid painted text &#8216;True/False&#8217; over images in boolean-type cells.</li>
<li>[BUG] Fixed row moving bug when .NetGrid under certain conditions, could throw an exception.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/netgrid-v2-10-1-has-been-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NetGrid v2.9.3 has been released.</title>
		<link>http://www.blog.dapfor.com/netgrid-v2-9-3-has-been-released</link>
		<comments>http://www.blog.dapfor.com/netgrid-v2-9-3-has-been-released#comments</comments>
		<pubDate>Wed, 16 Oct 2013 20:38:04 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[bug fixing]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[bugfix]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=232</guid>
		<description><![CDATA[A new grid version containing mostly error fixes and performance improvements has been released. The following improvements have been made: [NEW] Significantly improved cell painting performance. Fixed an error with the grid re-painting the entire row on a notification from a field for which the column is hidden or non-existent. [NEW] Improved the Grid’s disposal [...]]]></description>
			<content:encoded><![CDATA[<p>A new grid version containing mostly error fixes and performance improvements has been released.</p>
<p>The following improvements have been made:</p>
<ul>
<li>[NEW] Significantly improved cell painting performance. Fixed an error with the grid re-painting the entire row on a notification from a field for which the column is hidden or non-existent.</li>
<li>[NEW] Improved the Grid’s disposal algorithm. Handling of the situation when a grid can be disposed in the main thread and receive notifications from a non-GUI thread at the same time has been fixed as compared to the previous version.</li>
</ul>
<p>The following bugs have been fixed:</p>
<ul>
<li>[BUG] Fixed an error when a grid smaller than 20 pixels sometimes could generate exceptions on cell painting.</li>
<li>[BUG] Fixed rendering error when paining merged columns in RTL modе.</li>
<li>[BUG] Fixed header painting error with freezed columns in RTL mode.</li>
<li>[BUG] Fixed an error when moved rows stopped receiving notifications from data source when a grid unsubscribed a row from a datasource with drag&amp;drop operations.</li>
<li>[BUG] Fixed a <a href="http://doc.dapfor.com/net-suite/html/T_Dapfor_Net_Editors_CheckBoxEditor.htm">CheckBoxEditor</a> error when the grid could generate exceptions on partial editor visibility.</li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/netgrid-v2-9-3-has-been-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NetGrid v2.9.2 has been released.</title>
		<link>http://www.blog.dapfor.com/netgrid-v2-9-2-has-been-released</link>
		<comments>http://www.blog.dapfor.com/netgrid-v2-9-2-has-been-released#comments</comments>
		<pubDate>Mon, 05 Aug 2013 17:24:42 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[bug fixing]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.Net Grid features]]></category>
		<category><![CDATA[INotifyPropertyChanged]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=227</guid>
		<description><![CDATA[A significant increase in productivity when working with objects that implement the INotifyPropertyChanged interface The following bug has been fixed: [BUG] Fixed a bug where the grid redraw the content of the entire row upon receiving notification from INotifyPropertyChanged interface for missing or hidden column. [BUG] Fixed minor bugs in the designer.]]></description>
			<content:encoded><![CDATA[<p>A significant increase in productivity when working with objects that implement the <a href="http://msdn2.microsoft.com/es-es/library/ms133020" target="_blank">INotifyPropertyChanged</a> interface</p>
<p>The following bug has been fixed:</p>
<ul>
<li>[BUG] Fixed a bug where the grid redraw the content of the entire row upon receiving notification from <a href="http://msdn2.microsoft.com/es-es/library/ms133020" target="_blank">INotifyPropertyChanged</a> interface for missing or hidden column.</li>
<li>[BUG] Fixed minor bugs in the designer.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/netgrid-v2-9-2-has-been-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NetGrid v2.9.0 has been released. New features and bug fixes</title>
		<link>http://www.blog.dapfor.com/netgrid-v2-9-0-has-been-released-new-features-and-bug-fixes</link>
		<comments>http://www.blog.dapfor.com/netgrid-v2-9-0-has-been-released-new-features-and-bug-fixes#comments</comments>
		<pubDate>Wed, 05 Jun 2013 20:19:51 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[bug fixing]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.Net Grid features]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=215</guid>
		<description><![CDATA[We are glad to introduce a new grid version with improved performance and stability. We have added dozens new tests to cover various grid functions. We want to thank our customers for their feedback on products and ease of use and critical comments that help us make our products best on the market. The following [...]]]></description>
			<content:encoded><![CDATA[<p>We are glad to introduce a new grid version with improved performance and stability. We have added dozens new tests to cover various grid functions. We want to thank our customers for their feedback on products and ease of use and critical comments that help us make our products best on the market.</p>
<p>The following features have been added:</p>
<ul>
<li>[NEW] Added column filter serialization</li>
<li>[NEW] Reengineered grid designer introducing intuitive and convenient user interface.</li>
<li>[NEW] Significantly improved grid performance with selection large data volumes.</li>
<li>[NEW] Overall performance improvement.</li>
</ul>
<p>The following bugs have been fixed:</p>
<ul>
<li>[BUG] Fixed an error with the grid not unsubscribing from objects with composite properties when objects are removed from the grid.</li>
<li>[BUG] Fixed an error with Dapfor.Net.dll not appearing in the list of available assemblies in Visual Studio.</li>
<li>[BUG] Fixed an error with Column.Appearance property hiding cell highlighting.</li>
<li>Minor bug fixes</li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/netgrid-v2-9-0-has-been-released-new-features-and-bug-fixes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Application.DoEvents() in real-time applications is dangerous!</title>
		<link>http://www.blog.dapfor.com/using-application-doevents-in-real-time-applications-is-dangerous</link>
		<comments>http://www.blog.dapfor.com/using-application-doevents-in-real-time-applications-is-dangerous#comments</comments>
		<pubDate>Tue, 06 Nov 2012 11:03:57 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[DoEvents]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=192</guid>
		<description><![CDATA[It has been numerously written that Application.DoEvents() method is not desirable, especially for high-performance applications. There are many reasons for this starting from message processing procedure and ending with non-evident problems with application response  to user activity and code execution. In most cases programmers use this method without thinking of consequences or its working principle. [...]]]></description>
			<content:encoded><![CDATA[<p>It has been numerously written that<strong> Application.DoEvents()</strong> method is not desirable, especially for high-performance applications. There are many reasons for this starting from message processing procedure and ending with non-evident problems with application response  to user activity and code execution.</p>
<p>In most cases programmers use this method without thinking of consequences or its working principle. <a href="http://msdn.microsoft.com/en-us//library/system.windows.forms.application.doevents.aspx">MSDN documentation</a> says that this method processes messages in queue and when there are no more messages it stops working and passes control to the next code.<br />
In simplified form this method looks as follows:<br />
<code><br />
NativeUnsafeMethods.MSG msg;<br />
while (PeekMessage(out msg))<br />
{<br />
TranslateMessage(ref msg);<br />
DispatchMessage(ref msg);<br />
}</code></p>
<p>However, we may wonder what happens when application is intensively rendering controls, synchronizing threads and performing other operations in GUI thread? In such situation message queue always contains messages that don’t let method finish its work. As the result, the end user won’t notice the difference in application behavior as<strong> Application.DoEvents()</strong> will process executing messages, including WM_PAINT messages, i.e. controls will be redrawn and the program will not slow down. However, code execution will stop on <strong>Application.DoEvents()</strong> method. If there are important operations after this method, they will not be executed until message queue is freed. We have often seen the situation when application was updating stock market prices and in times of high volatility prices were updated with noticeable delays!!!</p>
<p>A simple example of the problem is shown below. Demo application intensively synchronizes threads and paints data. Main GUI thread continuously processes messages (including synchronization messages and WM_PAINT messages). Clicking Start button calls Application.DoEvents() once, and in normal situation it should immediately return control to subsequent code. However, in this example the things are different! This method is followed by MessageBox.Show(…) that doesn’t display anything.<br />
If demo application is fully covered with any other window or collapsed in the taskbar, Windows stops sending WM_PAINT messages and as the result of it message queue becomes empty, <strong>Application.DoEvents()</strong> method stops and MessageBox.Show(…) is executed.</p>
<p><a href="http://www.blog.dapfor.com/using-application-doevents-in-real-time-applications-is-dangerous/doevents" rel="attachment wp-att-194"><img class="size-full wp-image-194 alignleft" title="DoEvents" src="http://www.blog.dapfor.com/wp-content/uploads/2012/11/DoEvents.png" alt="" width="505" height="311" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Download <a href="http://dapfor.com/downloads/net-suite-examples/DoEventsExample.zip">DoEventsExample.zip</a></p>
<p>Therefore, before using <strong>Application.DoEvents()</strong> programmers should look at application architecture and ask themselves whether this method is really necessary. If application code really requires <strong>Application.DoEvents()</strong>, we have added <strong>Dapfor.Net.Editors.MessageQueueHelper</strong> class starting from version 2.8.4. This class has similar behavior but it also supports maximum execution time limit. If there are no more messages in queue, <strong>MessageQueueHelper</strong> also stops and passes control to the subsequent code.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/using-application-doevents-in-real-time-applications-is-dangerous/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NetGrid v2.8.4 has been released. Improvements when CPU is heavily loaded.</title>
		<link>http://www.blog.dapfor.com/netgrid-v2-8-4-has-been-released-improvements-when-cpu-is-heavily-loaded-2</link>
		<comments>http://www.blog.dapfor.com/netgrid-v2-8-4-has-been-released-improvements-when-cpu-is-heavily-loaded-2#comments</comments>
		<pubDate>Mon, 29 Oct 2012 22:59:48 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[bug fixing]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[editing]]></category>
		<category><![CDATA[improvements]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=187</guid>
		<description><![CDATA[This version contains bug fixes and performance improvements. The following features have been added: [NEW] Greatly improved the reliability and responsiveness of the grid when the CPU is heavily loaded. The following bugs have been fixed: [BUG] Fixed a bug in the column configurator which in some cases does not allow reordering of visible columns. [...]]]></description>
			<content:encoded><![CDATA[<p>This version contains bug fixes and performance improvements.</p>
<p>The following features have been added:</p>
<ul>
<li>[NEW] Greatly improved the reliability and responsiveness of the grid when the CPU is heavily loaded.</li>
</ul>
<p>The following bugs have been fixed:</p>
<ul>
<li>[BUG] Fixed a bug in the column configurator which in some cases does not allow reordering of visible columns.</li>
<li>[BUG] Fixed a bug where merged columns were drawn with artifacts.</li>
<li>[BUG] Fixed a bug when the grid incorrectly draws cells if there are simultaneously visible grouped rows and child header.</li>
<li>[BUG] Fixed a bug when the grid incorrectly displays a vertical scrollbar if there are simultaneously visible grouped rows and child header.</li>
<li>Minor bug fixes</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/netgrid-v2-8-4-has-been-released-improvements-when-cpu-is-heavily-loaded-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net performance. Practical recommendations</title>
		<link>http://www.blog.dapfor.com/net-performance-practical-recommendations</link>
		<comments>http://www.blog.dapfor.com/net-performance-practical-recommendations#comments</comments>
		<pubDate>Tue, 15 May 2012 21:07:42 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=167</guid>
		<description><![CDATA[Even the best performing component can be hindered by incorrect use. Below we provide practical recommendations on what should be used or avoided in application programming. Following the tips below you will be able to create applications with the same efficiency as this demo application. We also provide source codes for this example to show [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: center; margin-bottom: 30px;"><img src="http://www.dapfor.com/images/ProductPicsImages/Performance.jpg" alt="" align="middle" /></div>
<p>Even the best performing component can be hindered by incorrect use. Below we provide practical recommendations on what should be used or avoided in application programming. Following the tips below you will be able to create applications with the same<br />
efficiency as <a href="http://www.dapfor.com/downloads/net-suite-examples/Dapfor.Grid.PerfDemo.zip" target="_blank">this demo application</a>. We also provide <a href="http://www.dapfor.com/downloads/net-suite-examples/Dapfor.Grid.PerfDemo_src.zip" target="_blank">source codes</a> for this example to show how easy it is.</p>
<ul>
<li>It is supposed that programmers already know general principles of application design. Nevertheless, we shall provide  some useful links for better understanding of .Net environment and tools for writing managed code: <a href="http://msdn.microsoft.com/en-us/library/ms973852" target="_blank">Writing Faster Managed Code: Know What Things Cost</a></li>
<li>It is necessary to pay attention to <a href="http://www.dapfor.com/en/net-suite/net-grid/features/performance">grid characteristics</a> in different working modes, to evaluate data volume to be  displayed and to find a relevant chart for better understanding of grid use.</li>
<li>Use ThreadSafeBindingList&lt;T&gt; instead of BindingList&lt;T&gt; for the following reasons:1. BindingList&lt;T&gt; has poor implementation when working with objects that implement INotifyPropertyChanged interface.  <a href="http://www.dapfort.com/en/net-suite/net-grid/tutorial/threadsafe-bindinglist">Here</a>you can find more information on BindingList&lt;T&gt; performance issues.  Use ThreadSafeBindingList&lt;T&gt; instead, as it doesn’t allow BindingList&lt;T&gt; to subscribe to events of objects that it contains.2. Another reason to use ThreadSafeBindingList&lt;T&gt; instead of BindingList&lt;T&gt; is related to implementation of  MulticastDelegate used in events. With one subscriber, this delegate consumes minimum memory resources, but when there are two  or more subscribers, it creates an internal subscriber collection that increases memory consumption dramatically. The grid always subscribes  to objects that implement INotifyPropertyChanged interface and BindingList&lt;T&gt; is the second subscriber.</li>
<li>If BindingList&lt;T&gt; is used together with objects implementing INotifyPropertyChanged interface, it is  better to avoid firing notifications with non-existent data object properties. It is mainly required because when a binding  list receives such notification it checks whether the firing object has the specified property. If the firing object doesn’t  have such property, the BindingList&lt;T&gt; generates <strong>ListChanged</strong> event specifying <strong>Reset</strong> reason and forcing the grid to rebuild all its contents.</li>
<li>Avoid using INotifyPropertyChanged interface, unless it is required. If the object doesn’t change at run-time, it is better not to use this interface to save memory and CPU resources.</li>
<li>Add data to the end of collection (List&lt;T&gt;, BindingList&lt;T&gt;, ThreadSafeBindingList&lt;T&gt; etc). Otherwise, internal implementation of indexed collections will move and re-index all data starting from the newly added index.</li>
<li>Avoid adding data to a binding list with more than 10 000 items when the grid is sorted. Stop sorting to improve performance.  However, if you need to add large amounts of data in real-time to the beginning of the grid, it&#8217;s better to use the following:
<div>
<pre>grid.Sort.Enabled = false;
grid.DataSource = _datasource_;</pre>
<pre>//Add a single object to the beginning of the grid
grid.Nodes.Insert(0, _new_object_);

//Add a single object to the beginning of the binding list
IBindingList bl = ...;
bl.Insert(0, _new_object_);</pre>
</div>
</li>
<li>Although the grid is thread-safe with INotifyPropertyChanged and IBindingList interfaces, use the GUI thread  to work with it. This is mainly important for adding large data volumes. Some optimization algorithms work better when there  is no need to switch between threads. Please also note that BindingList&lt;T&gt; is not thread-safe.</li>
<li>Have only one message loop per application. Don&#8217;t create grids in different threads.Let us assume that the computer resources are not limitless. Theoretically the maximum performance can be obtained  if the number of threads equals to the number of processor cores. While a lot of threads are creating, they aren’t working in parallel.  In this case cores allocate time slices to threads based on their priority and consistently perform context switches (context switch is relatively expansive operation). Note, maximum time slice is about 10-15 msec.We have also take into account that each control paints its content in the GDI/GDI+ device (via the Graphics object).  While painting from one thread all others wait for GDI device to perform painting in its turn. Therefore if we start many  message loops – it doesn’t mean that we accelerate the application. In other words the application losses time on context  switches and on drawing in GDI device.
<p>From our point of view the application should have only one message pump. Windows has additional mechanisms  to optimize content drawing and we are not sure that they work in case of multithreaded environment. Of course,  business logic can work in any thread, but the graphical thread should be only one in the application.</li>
<li>Use MethodInvoker to synchronize threads.In multi-threaded applications every call should be synchronized with the main thread containing windows message loop. Both <strong>Control.Invoke</strong> and <strong>Control.BeginInvoke</strong>methods may accept  different delegate types and their parameters. However, this causes a serious performance issue as they call  Delegate.DynamicInvoke(params object[] args), which in turn uses low-performance reflection. At the same time, for some delegates such as EventHandler, MethodInvoker and WaitCallback the code is called directly.  In the time of code execution the delegate is checked for belonging to one of the above types with specified number of parameters, and if it doesn’t – DynamicInvoke() is called.From practical point of view the synchronization process should look as follows:
<div>
<pre>someControl.BeginInvoke(new MethodInvoker(delegate
{
    //a code here
}));</pre>
</div>
</li>
<li>Use objects of arbitrary classes instead of collections of values of string[] type, etc. It is more convenient and objects of arbitrary classes consume less memory than string collections.</li>
<li>Don’t format values directly in data objects, i.e. if an object property is to return date, this field should return DateTime object type instead of string type. Use <a href="http://www.dapfort.com/en/net-suite/net-grid/tutorial/data-formatting">data formatting</a> if needed. If properties return strings, they can be <a href="http://www.dapfort.com/en/net-suite/net-grid/tutorial/data-sorting">compared incorrectly</a>during data sorting. Besides, comparing two strings requires more CPU resources than comparing two DateTime objects.
<div>
<pre>class DateExample
{
    ...

    //Bad idea
    public string FormattedDate
    {
        get { return string.Format("{0:yyyy-MM-dd}", _date); }
    }

    //Good idea: the property should return non-formatted value
    [Format("yyyy-MM-dd")]
    public DateTime Date
    {
        get { return _date; }
    }
}</pre>
</div>
</li>
<li>Use the <a href="http://www.dapfort.com/en/net-suite/net-grid/tutorial/event-driven-model">event-driven model</a>, if possible. On global scale it is more efficient than searching for rows in one or more grids with dynamically changing data.</li>
<li>Share the same business objects in different grids.  Use <a href="http://www.dapfort.com/en/net-suite/net-grid/tutorial/data-binding">declarative binding</a>. This simplifies the application code and significantly reduces memory consumption.</li>
<li>Avoid using unnecessary wrappers. Use declarative binding instead of <a href="http://www.dapfor.com/en/net-suite/net-grid/features/composite-objects">creating intermediate classes</a>.</li>
<li>Use statically declared EventArgs for data fields to avoid creating numerous short-lived objects when sending notifications via INotifyPropertyChanged interface.
<div>
<pre>class MyDataObject : INotifyPropertyChanged
{
    private static readonly PropertyChangedEventArgs Value1Args = new PropertyChangedEventArgs("Value1");

    private string _value1;

    public string Value1
    {
        get { return _value1; }
        set
        {
            if (_value1 != value)
            {
                _value1 = value;

                //Bad idea: short-lived object is created
                FirePropertyChanged("Value1");

                //Good idea: notify with an immutable static object
                FirePropertyChanged(Value1Args);
            }
        }
    }

    private void FirePropertyChanged(string fieldName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(fieldName));
        }
    }

    private void FirePropertyChanged(PropertyChangedEventArgs args)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, args);
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}</pre>
</div>
</li>
<li>Work with business logic objects directly instead of calling Cell.Value/Row.DataAccessor["fieldId"].ValueTypeDescriptor/PropertyDescriptor are used to display values in cells when working with arbitrary data types.<br />
The following code demonstrates value extraction from data objects.</p>
<div>
<pre>MyDataObject dataObject = ...;
dataObject.Value1 = "some value";

PropertyDescriptor property = TypeDescriptor.GetProperties(dataObject)["Value1"];
object value = property.GetValue(dataObject);</pre>
</div>
<p>This working principle is the same for all grids of all vendors. The main issue is that PropertyDescriptor.GetValue() method uses reflection. NetGrid has an optimization that enables it to receive notifications from INotifyPropertyChanged/IBindingList without calling data object getters. Values are required only at the time of painting and only for visible cells. If the grid has a lot of rows, most of them are invisible and this approach significantly saves CPU resources. It is worth considering in application development. As an example, let’s review subscription to Grid.RowUpdated event:</p>
<div>
<pre>grid.RowUpdated += delegate(object sender, GridRowUpdateEventArgs e)
{
    //This callback is called each time when a notification from INotifyPropertyChanged received.

    //Using of custom object will reduce CPU consumption
    MyDataObject myObject = (MyDataObject) e.Row.DataObject;
    decimal lastPrice = myObject.LastPrice;

    //The following call will use the reflection. Try to avoid.
    lastPrice = (decimal) e.DataField.Value;
};</pre>
</div>
</li>
<li>Use new Row.IsInVisibleBounds property added to version 2.8.0.When updating data in real time in applications, the grid stores highlighting information for each updated cell. This default behavior causes serious consumption of memory resources in addition to CPU resource consumption  due to processing large volume of information. As most updates can occur outside the visible area, the programmer can save CPU resources by using the new property.
<div>
<pre>//Disable authomatic highlighting (from INotifyPropertyChnaged interface)
grid.Highlighting.Enabled = false;

//This callback is called each time when a notification from INotifyProeprtyChanged received.
grid.RowUpdated += delegate(object sender, GridRowUpdateEventArgs e)
{
    //Handle updates only for visible rows
    if(e.Row.IsInVisibleBounds)
    {
        //Using of custom object will reduce CPU consumption
        MyDataObject myObject = (MyDataObject)e.Row.DataObject;
        double delta = myObject.LastPrice - myObject.PrevPrice;
        if(delta != 0)
        {
            Color color = delta &gt; 0 ? Color.Green : Color.Red;
            //highlight the 'LastPrice' cell with specified semi-transparent color for 2 seconds
            e.Row["LastPrice"].Highlight(TimeSpan.FromSeconds(2), Color.FromArgb(50, color));
        }
    }
};</pre>
</div>
<p>When this optimization is used, vertical scrolling may bring rows without cell highlighting information to the visible area and the user will not see cell highlights that were made before rows get to visible area of the grid. This concerns only highlighting information, while text and other cell content will display correctly. The programmer should decide whether to use such optimization or not.</li>
<li>While construction of the hierarchy is preferable to collapse root rows:
<div>
<pre>grid.RowAdded += delegate(object sender, GridRowEventArgs e)
{
    e.Row.Expanded = false;
};</pre>
</div>
</li>
<li>Turn off fading effect when building real-time applications:
<div>
<pre>grid.Highlighting.Fading = false;</pre>
</div>
</li>
<li>Avoid settins colors, fonts in rows and cells because of high memory consumption (Colors and fonts are stored per cell or row). Use <strong>Grid.Appearance / Header.Appearence</strong> properties  and <strong>Grid.PaintRow / Grid.PaintCell</strong>event handlers instead:
<div>
<pre>//The back color is stored per cell. If grid has thousands rows, memory consumption can be very high.
Cell cell = grid.Rows[0]["Price"];
cell.Appearance.BackColor = Color.Red;

//The back color is stored per row. If grid has thousands rows, memory consumption can be very high.
Row row = grid.Rows[0];
row.Appearance.BackColor = Color.Blue;

//Good idea: colors are stored per grid
grid.Appearance.EvenRows.BackColor = Color.FromArgb(10, Color.Red);
grid.Appearance.OddRows.BackColor = Color.FromArgb(10, Color.Blue);

//Good idea: colors are stored per header (therefore per hierarchical level)
Header header = grid.Headers[0];
header.Appearance.EvenRows.BackColor = Color.FromArgb(10, Color.Red);
header.Appearance.OddRows.BackColor = Color.FromArgb(10, Color.Blue);

//Good idea: colors are specified only at painting time
grid.PaintRow += delegate(object sender, PaintRowEventArgs e)
{
    e.Appearance.BackColor = e.Row.VisibleIndex % 2 == 0
                                 ? Color.FromArgb(10, Color.Red)
                                 : Color.FromArgb(10, Color.Blue);
};</pre>
</div>
</li>
<li>Try avoiding reflection.</li>
<li>Be very careful about creating temporary objects as it may result in memory pressure and make garbage  collector collect unused objects more frequently. Please note that when garbage is collected, all application threads  are temporarily stopped.</li>
<li>Don’t use finalizers in objects unless necessary.</li>
</ul>
<p>We hope that these simple recommendations will help you create efficient and high-performing applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/net-performance-practical-recommendations/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why BindingList is slow with objects implementing INotifyPropertyChanged interface</title>
		<link>http://www.blog.dapfor.com/why-bindinglist-is-slow-with-objects-implementing-inotifypropertychanged-interface</link>
		<comments>http://www.blog.dapfor.com/why-bindinglist-is-slow-with-objects-implementing-inotifypropertychanged-interface#comments</comments>
		<pubDate>Thu, 29 Mar 2012 18:59:31 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[Data binding]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[BindingList]]></category>
		<category><![CDATA[INotifyPropertyChanged]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=139</guid>
		<description><![CDATA[A BindingList&#60;T&#62; is the main tool for binding objects to grids. It is a container that may notify subscribers when data is added or removed. For this purpose it provides public ListChanged event that specifies collection changes with ListChangedType. Besides changing the collection itself (adding, removing, etc) the binding list notifies of data object changes. [...]]]></description>
			<content:encoded><![CDATA[<p>A <strong>BindingList&lt;T&gt;</strong> is the main tool for binding objects to grids. It is a container that may notify subscribers when data is added or removed. For this purpose it provides public ListChanged event that specifies collection changes with ListChangedType. Besides changing the collection itself (adding, removing, etc) the binding list notifies of data object changes. In other words, when data is added to collection <strong>BindingList&lt;T&gt;</strong> checks whether it implements <strong>INotifyPropertyChanged</strong> interface. If it is implemented, the collection subscribes to each object changes and forwards notifications as <strong>IBindingList.ListChanged</strong> events with <strong>ListChangedType.ItemChanged</strong> type and with specified PropertyDescriptor that is searched by reflection. </p>
<p>It’s worth mentioning that handler of <strong>INotifyPropertyChanged</strong> notification is very poorly implemented. Low performance reflection is used for searching PropertyDescriptor and internal cache is very poorly organized thus significantly reducing performance. Specifically when the <strong>BindingList&lt;T&gt;</strong> receives notifications of new object, it compares this object with the previous object that was used for notification. If they are not identical, the binding list does a terrible thing – it runs through all objects to get the index of the notifying object. This seriously impacts performance when there are a lot of elements. When the number of elements is about 100 000, handling of a single notification takes about 1 ms, which is unacceptable for most applications. </p>
<p>In actual applications <strong>ListChangedType.ItemChanged</strong> event with <strong>ListChangedType.ItemChanged</strong> flag and set PropertyDescriptor is handled quite rarely. However, it is hard to disable <strong>INotifyPropertyChanged</strong> handling in a <strong>BindingList&lt;T&gt;</strong> via simple means. The only acceptable method of disabling handling is to use reflection. The thing is that the binding list in its constructor checks whether the data type implements <strong>INotifyPropertyChanged</strong> interface and sets <strong>raiseItemChangedEvents</strong> private variable to true if it does. Otherwise it is set to false. This variable influences only subscriptions to <strong>INotifyPropertyChanged</strong> interface. There is no direct access to this variable and it can be modified only via reflection. An example of code for this is provided below. </p>
<pre>
class CustomBindingList&lt;T&gt; : BindingList&lt;T&gt;
{
    public CustomBindingList()
    {
        FieldInfo fi = typeof (BindingList&lt;T&gt;).GetField("raiseItemChangedEvents",
                               BindingFlags.Instance | BindingFlags.NonPublic);
        if (fi != null)
        {
            fi.SetValue(this, false);
        }
    }
}
</pre>
<p><br/></p>
<p>The above implements fully functional binding list with disabled handling of <strong>INotifуPropertyChanged</strong> interface events. At the same time the binding list notifies subscribers of adding or removing data just like in standard implementation of this container. </p>
<p>Some figures: In standard binding list implementation handling of 1000 notifications in 100 000 container took more than 600 msec. In optimized version this time – 0 since the container no longer subscribes to data objects. Besides that, no subscription enables memory saving. </p>
<p>This article concerns only binding list performance aspects. Another important aspect of working with binding lists <strong>INotifyPropertyChanged</strong> is their use in <a href="http://www.dapfor.com/en/net-suite/net-grid/tutorial/data-binding">advanced binding</a>.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/why-bindinglist-is-slow-with-objects-implementing-inotifypropertychanged-interface/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
