C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Maximizing Application Performance under .NET Framework


Posted Date: 05 Aug 2004    Resource Type: Articles    Category: .NET Framework
Author: Muralidharan RamakrishnanMember Level: Gold    
Rating: 1 out of 5Points: 7



Introduction

From my experience , i have found that when carefully optimized, you can maximize your application performance up to 30%
using these .net optimization techniques. Many programmers try to write the code first and optimize later, that is a bad design
principle, learn to implement these best practices throughout the design, development and deployment cycles.
Try them and feel the difference.


1) Use Option Explicit and Option Strict

2)Donot Late Bind

Calls on Object cause late binding. Such binding requires work at runtime. The binding process in .net is more complex than in VB6. Using operators on objects can cause late binding:

eg:-


Dim o, o1, o2 As Object
o = o1 + o2 ' Late bound




3)Use the Right Types

Understand the 2 kinds of types: Value types and Reference Types. The reference types are allocated on heaps and copies do not attract a performance cost whereas the value types are allocated "in place" and copies have a performance cost.

There is no "one rule that fits all". The rule of thumb is to use value types for small objects and reference type for large objects.


4)Avoid Slow Conversions

Understand boxing and unboxing. When you assign a value type to an object a boxing operation occurs, similarly when you convert an object type to original type an unboxing occurs. Boxing and unboxing can prove as bottlenecks to application
performance. Use Option Strict On to catch such slow type conversions


5)Beware of Multidimensional Arrays and uninitialized arrays

Make sure you use ArrayList object to avoid usage of "ReDim", "Preserve" keywords. Runtime memory allocation is not recommended practice in programming world. Use array of arrays instead of multi-dimensional arrays, they are relatively quicker.


6) String Tips

Strings are now immutable in .net Framework. There are a few nibble areas you need to be careful.

When you use "&" operator actually is new string is created to produce the concatenated string. That means more memory allocation!!!. Use System.Text.StringBuilder to build long concatenated strings, it is extremely
efficient.

Word of caution do not do this. It is extremely inefficient try using replace instead


mid(str,2,4)="abcd"


If globalization isn't important: Use Option Binary instead of Text. Use ".ToString" to perform string formats instead of Format function

7) Minimize Exceptions

Use exceptions only for errors, exceptions are not events. I see many people using it to pass error messages back to calling routine. Please be aware that throwing exception is extremely expensive!!!

For VB guys use Try ...Catch instead of "On Error" statements

8) Make your calls Chunky not Chatty

Calls across your runtime boundaries are expensive. Be careful when you use Declare Statements,COM objects,AppDomains and Remoting. When you design calls ensure you minimize calls and maximize data!!!


Other Tips

Don't
--> Allocate memory when you donot need.
--> Have large number of local variables.
--> write really large methods(rule of thumb is 25 lines, more than that consider refactoring your code).

---> Use Overridable Methods Only when needed, calls to such methods are little expensive

---> Use Release Builds

---> Remove integer overflow checks if your application is not calcuation intensive





Responses

Author: Ravi Makwana    06 Oct 2004Member Level: Bronze   Points : 0
A nice & valuable article. This will prove to be a control measure for performance of any application.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Using Windows Fax Service of Windows 2000 in C#
Previous Resource: Difference between string and System.String?
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use