<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx</link><description>Dare writes about a perf and memory usage issue in RSS Bandit. I've come across this at least 10 times in my career - developers tend to underestimate the amount of time it takes to update a UI. I've seen cases where 70% of the cpu time is going towards</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#451306</link><pubDate>Sat, 13 Aug 2005 22:53:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451306</guid><dc:creator>CN</dc:creator><description>I even remember a codebase where a certain operation was quite slow. In it was a line like this:&lt;br&gt;&lt;br&gt;if (itemCount % 16) updateGui();&lt;br&gt;&lt;br&gt;(this was in C++, so an int to bool implicit cast was done)&lt;br&gt;&lt;br&gt;As you might imagine, inverting that condition boosted performance quite a lot.</description></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#451345</link><pubDate>Sun, 14 Aug 2005 01:01:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451345</guid><dc:creator>Drew</dc:creator><description>CN: Inverting that condition? Meaning update for 15 of every 16 items added? The original code was doing what Eric suggested (not updating for every change, but sort of &amp;quot;batching&amp;quot; changes), though evidently the timing wasn't right in your case. And why bother skipping that 1 of every 16? If the perf in your was better when updating on 15 out of 16 item adds it probably would have been better still to remove that condition altogether.</description></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#451357</link><pubDate>Sun, 14 Aug 2005 01:36:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451357</guid><dc:creator>Oleg Mihailik</dc:creator><description>I have simple and well-behaving code for this purpose.&lt;br&gt;&lt;br&gt;DateTime nextUpdate = DateTime.Now;&lt;br&gt;&lt;br&gt;while( &amp;lt;cycle&amp;gt; )&lt;br&gt;{&lt;br&gt;    // ... working&lt;br&gt;&lt;br&gt;    if( DateTime.Now&amp;gt;=nextUpdate )&lt;br&gt;    {&lt;br&gt;        // ... update UI&lt;br&gt;        nextUpdate = DateTime.Now + TimeSpan.FromSeconds( 0.3 );&lt;br&gt;    }&lt;br&gt;}</description></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#451403</link><pubDate>Sun, 14 Aug 2005 06:09:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451403</guid><dc:creator>PatriotB</dc:creator><description>Inverting that condition is what he meant.  Look closely at the line:&lt;br&gt;&lt;br&gt;if (itemCount % 16) updateGui(); &lt;br&gt;&lt;br&gt;The way it's written it will update 15 out of 16 times.  Inverting it will do one out of 16:&lt;br&gt;&lt;br&gt;if (!(itemCount % 16)) updateGui();&lt;br&gt;&lt;br&gt;This will cause updateGui to only be called when (itemCount % 16) is zero.</description></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#451497</link><pubDate>Sun, 14 Aug 2005 14:15:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451497</guid><dc:creator>damien morton</dc:creator><description>What you want to do is trigger a timer to fire off x milliseconds after a change has happened. This means that if no changes happen, no updates are triggered, and that the maximum update rate will be x milliseconds.</description></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#451649</link><pubDate>Mon, 15 Aug 2005 06:04:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451649</guid><dc:creator>G. Dog</dc:creator><description>Damien is correct, the right solution is to use a watchdog timer that fires and updates the GUI. Every time a backend change happens you reset the timer. This is the ideal solution in all cases.&lt;br&gt;</description></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#451669</link><pubDate>Mon, 15 Aug 2005 09:03:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451669</guid><dc:creator>damien morton</dc:creator><description>Oh yeah - one other thing... GUI updating wouldnt be so much of a problem if GDI+ wasnt so dog slow.&lt;br&gt;&lt;br&gt;For basic things like rendering text, GDI+ is nearly an order of magnitude slower than GDI. As a result, you end up having to be much more clever about  arranging incremental updates to the screen.&lt;br&gt;&lt;br&gt;GDI+ performance hasnt improved in Whidbey beta 2. I have no idea what text rendering performance is like under Avalon. I cant imagine that the GDI+ rendering model will ever be hardware accelerated - its just too complex.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>Dare on RSS Bandit Performance Problems</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#452068</link><pubDate>Tue, 16 Aug 2005 12:02:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:452068</guid><dc:creator>notgartner.com: Mitch Denny's Blog</dc:creator><description /></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#452089</link><pubDate>Tue, 16 Aug 2005 13:20:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:452089</guid><dc:creator>mihailik</dc:creator><description>Damien, your solution is wrong.&lt;br&gt;&lt;br&gt;If you run long-running task and timer callback on 2 different threads, you have to battle race conditions. Measurement will be much harder and complex to implement than primary work itself.&lt;br&gt;&lt;br&gt;If your timer will be run on UI thread (e.g. WinForms timer), you will get no timer hits until work is done completely. It means your progress bar will show 0%, wait, and then 100%.&lt;br&gt;&lt;br&gt;So using timers for progress indication is not productive.</description></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#452091</link><pubDate>Tue, 16 Aug 2005 13:26:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:452091</guid><dc:creator>mihailik</dc:creator><description>1. Whidbey and GDI.&lt;br&gt;There are cool tools in Whidbey, that particularly allows GDI text rendering. See TextRenderer class and VisualStyles namespace. These facility is system-supplied renderer set for many kinds of controls.&lt;br&gt;&lt;br&gt;2. GDI vs GDI+.&lt;br&gt;I agree, GDI+ is noticeable slower than GDI. But I believe GDI+ speed is acceptable for most GUI tasks. I have seen enough examples of GDI+ animated UIs.</description></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#452175</link><pubDate>Tue, 16 Aug 2005 18:02:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:452175</guid><dc:creator>damien morton</dc:creator><description>mihalik - perhaps I miscommunicated the time-based approach. It does work, and it works in a multithreaded environment. The actual mechanism use to implement this technique (thread.timer, form.timer) depends on the situation. The basic algorithm, that you should start a 'timer' when you get a change, then ignore subsequent changes until the 'timer' expires, after which you update and return to the initial state, is better than some of the alternatives (i.e. updates to every x millisecs).&lt;br&gt;&lt;br&gt;When I was testing Whidbey text rendering, I'm pretty sure I tried TextRenderer. Cant remember the exact results, but broadly, nothing has changed in Whidbey as far a text rendering speed goes. Of course, I was testing on an early version of Whidbey. I could try again. &lt;br&gt;&lt;br&gt;The problem is that the GDI+ rendering model is fundamentally a vector rendering model, which is great for doing fancy effects, but terrible for blasting out simple axis-aligned text. Even a high-end 3D graphics card wouldnt really help GDI+, because it supports a different rendering model. For that reason, I dont expect Avalon to have decent text rendering performance.&lt;br&gt;&lt;br&gt;&amp;quot;GDI+ speed is acceptable for most GUI tasks&amp;quot;. Hmm, yeah, except when it isnt. GDI+ can fill a 1024x768 screen with text approximately 6-8 times a second. GDI can do it 40-60 times a second. If you're writing a text editor, and you want to have fast page scrolling, you need a decent text renderer, and hardware acceleration helps. In the absence of fast text rendering, theres things you can do, i.e. by blitting the on-screen text around instead of re-rendering the whole page, but fundamentally, you are just tweaking the performance curve in some 'common' use cases, at the expense of enormous programmer effort.&lt;br&gt;&lt;br&gt;For the GUI tasks I work on, which involve blasting out real-time data into grid and graphs onscreen, simple text rendering can consume over 50% of CPU, even when gating updates to 250ms, and intelligently managing screen invalidations. Its a struggle.</description></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#454233</link><pubDate>Sun, 21 Aug 2005 21:15:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:454233</guid><dc:creator>damien morton</dc:creator><description>Hmm, juts found a document which describes the text rendering architecture in Avalon. It seems that if you have DX10 capable graphics hardware, then you will see a 10x improvment in text rendering performance from 100,000 to 1,000,000 glyphs per second.&lt;br&gt;&lt;br&gt;On my 1280x1024 screen, I can fit about 150*70 == 10,000 characters on a screen, which corresponds to the 10 frames per second refresh rate Ive been seeing with GDI+. With DX10 hardware, a 100fps rate could be achieved. Thats fast text rendering.&lt;br&gt;&lt;br&gt;That said, Avalon and DX10 hardware is several years off.&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: UI Updating can be hazardous to your performance...</title><link>http://blogs.msdn.com/ericgu/archive/2005/08/13/451292.aspx#454234</link><pubDate>Sun, 21 Aug 2005 21:16:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:454234</guid><dc:creator>damien morton</dc:creator><description>Oh - heres the link to that Avalon Text Rendering document.&lt;br&gt;&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://download.microsoft.com/download/1/8/f/18f8cee2-0b64-41f2-893d-a6f2295b40c8/TW04007_WINHEC2004.ppt"&gt;http://download.microsoft.com/download/1/8/f/18f8cee2-0b64-41f2-893d-a6f2295b40c8/TW04007_WINHEC2004.ppt&lt;/a&gt;</description></item></channel></rss>