Chapter 6: Improving Performance

Overview

Performance has to be one of the most frequent worries amongst developers - no one wants their code to run visibly slowly. Despite the huge power of modern processors and large amounts of RAM available, it's still not hard to design an application badly so that some bottleneck or piece of inefficient code causes a visible and unnecessary slowdown. As one obvious example, I never cease to be amazed when I ask Windows Explorer to delete one single file and it takes a couple of seconds to do so on my 1 GHz plus Athlon machine! Even without the burden of obviously poor design, there are some applications that place such intensive demands on a system that consideration of performance when coding them up is of vital importance. Traditionally, games are quoted as the main candidates here, but the same applies to some more complex database queries, and to intensive numerical code, and areas such as regular-expression processing. Any operations that need to be performed over a network can also impact performance.

Don't confuse performance with responsiveness. Performance is directly concerned with how long the computer takes to do something (including waiting times, for example, for network calls), whereas responsiveness is specifically about how quickly the computer reacts when the user does something. In this chapter, we'll concentrate on performance as a whole, though many of the same techniques we discuss will affect responsiveness as well. Generally, however, the user cannot perceive time intervals less than about a tenth of a second when judging the time between user input and the computer responding. This is sufficiently long that the performance of code may not be important. Often, what's more important for user responsiveness is that the computer or the thread isn't tied up doing something else when the user does something on the mouse or keyboard. Responsiveness is generally ensured by using correct multi-threaded techniques - I'll discuss these in .

The .NET Framework has brought with it the ability to write much more robust and secure code more easily than ever before. But it nevertheless does at the present time form a layer between your application and the Windows operating system, and basic common sense tells us that means it's going to contribute to some overhead. In this chapter, we're going to take a critical view of the .NET Framework from the performance perspective. We'll be spending some time looking at practical measures you can take to improve the performance of your applications, but I'll also look at some of the .NET CLR internals that are particularly relevant to performance. In particular, I shall cover:

  • Is it best to use the .NET Framework or stick with unmanaged code, if performance is an issue?

  • What optimizations the .NET Framework and the JIT compiler perform, and how to enable them.

  • Various tricks and tips that you can use to maximize performance for your unmanaged code.



Advanced  .NET Programming
Advanced .NET Programming
ISBN: 1861006292
EAN: 2147483647
Year: 2002
Pages: 124

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net