Presentation is loading. Please wait.

Presentation is loading. Please wait.

DEV394 Windows Forms Performance Tips And Tricks Mike Henderlight Development Manager.NET Client Team Microsoft Corporation

Similar presentations


Presentation on theme: "DEV394 Windows Forms Performance Tips And Tricks Mike Henderlight Development Manager.NET Client Team Microsoft Corporation"— Presentation transcript:

1 DEV394 Windows Forms Performance Tips And Tricks Mike Henderlight Development Manager.NET Client Team Microsoft Corporation sburke@microsoft.com

2 Introduction Status of Windows Forms Performance Perceived vs. Actual Performance Areas of Focus Program Flow Drawing Startup Time Working Set Shutdown Wrap up

3 Status of Performance Runtime performance is very good Working set can be misleading CLR is sensitive to “memory pressure” Will allocate resources optimistically “Cold” application startup disk bound Many stress, leak, other issues fixed in v1.1 Only tactical performance work in v1.1, however

4 Basic Performance Techniques Don’t do work until you have to Remember, it’s “pay for play” Cache only when necessary – but it can be a powerful tool Don’t use exceptions in normal code flow Be aware of memory allocation – it’s very expensive

5 Windows Forms Performance Functions Methods for Batching Operations: BeginUpdate/EndUpdate BeginEdit/EndEdit Use Application.Idle to simulate asynchronous operations Beware of handle creations Always call Dispose when you can! Be careful with threads

6 Batching operations demo demo

7 Drawing Performance GDI+ designed for locale/device independent text rendering Lacks hardware acceleration Careful coding can result in good performance however Windows Forms has built in double buffering for Controls Image drawing trick of specifying a “premultiplied” format helps immensely. Important to use traditional drawing optimizing techniques of clipping, etc.

8 Optimizing Drawing in Windows Forms Applications demo demo

9 Optimizing Startup Time Startup time is the main area.NET needs to improve performance Primarily a Client issue – server applications are less concerned with this Faster hard drives make a big difference Can be mitigated by decreasing dependencies at startup

10 Techniques for Improving Startup “NGen” your assembly Do work on demand after the application is up and running Avoid loading extra assemblies and functionality Use progress UI or splash screens Remove any tracing switches or calls to config

11 Improving Startup Time and Perception – a walkthrough of optimizing an application demo demo

12 Do I Look Fat in This Runtime? What is Memory Pressure? Using available memory helps performance Minimizing, restoring app shows current “active” working set Not freeing references/disposing objects will hurt working set – can leak memory Remember event handlers hold references Applications generally shouldn’t be calling GC.Collect Always call Dispose when possible

13 Working Set and Memory Pressure demo demo

14 General Programming Tips Avoid using exceptions – they are very performance intensive Be very careful of overusing threads Use a StringBuilder for multiple concatenations If writing in C#, use unsafe code for manipulating native memory: private unsafe void WmWindowPosChanging(ref Message m) { WINDOWPOS* wp = (WINDOWPOS *)m.LParam; if ((wp->flags & WP_NOSIZE)) == 0) wp->cy += 100; }

15 More Tips… for is faster than foreach in critical codepaths Predefine Hashtable and Array sizes Be aware of initializing static and class initializers at class construction time Beware of operations that cause premature Handle creation or recreation Don’t create applications with thousands of controls. Windows has a limit of 10,000 per process, and much lower on Win9x. Consider owner-drawing your control or application.

16 Community Resources http://www.microsoft.com/communities/default.mspx Most Valuable Professional (MVP) http://www.mvp.support.microsoft.com/ Newsgroups Converse online with Microsoft Newsgroups, including Worldwide http://www.microsoft.com/communities/newsgroups/default.mspx User Groups Meet and learn with your peers http://www.microsoft.com/communities/usergroups/default.mspx

17 evaluations evaluations

18 © 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.


Download ppt "DEV394 Windows Forms Performance Tips And Tricks Mike Henderlight Development Manager.NET Client Team Microsoft Corporation"

Similar presentations


Ads by Google