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 »

General considerations to improve Performance of .NET Applications


Posted Date: 30 Jun 2009    Resource Type: Articles    Category: .NET Framework
Author: Viji RAJKUMARMember Level: Diamond    
Rating: 1 out of 5Points: 10



General considerations to be made to improve Performance of .NET Applications

1. Resource Cleanup
Failing to clean up resources is a common cause of performance and scalability
bottlenecks. Review your code to make sure all resources are closed and released as soon as possible. This is particularly important for shared and limited resources such as connections. Make sure your code calls Dispose (or Close) on disposable resources.

Make sure your code uses finally blocks or using statements to ensure resources are closed even in the event of an exception.


2. Exceptions
While structured exception handling is encouraged because it leads to more robust code and code that is less complex to maintain than code that uses method return codes to handle error conditions, exceptions can be expensive. Make sure you do not use exception handling to control regular application flow. Use it only for exceptional conditions. Avoid exception handling inside loops — surround the loop with a try/catch block instead if that is required. Also identify code that swallows exceptions or inefficient code that catches, wraps, and rethrows exceptions for no valid reason.


3. String Management

Excessive string concatenation results in many unnecessary allocations, creating extra work for the garbage collector. Use StringBuilder for complex string manipulations and when you need to concatenate strings multiple times. If you know the number of appends and concatenate strings in a single statement or operation, prefer the + operator. In ASP.NET applications, consider emitting HTML output by using multiple Response.Write calls instead of using a String Builder.

4. Threading:

Server-side code should generally use the common language runtime (CLR) thread
pool and should not create threads on a per-request basis. Review your code to ensure that appropriate use is made of the thread pool and that the appropriate
synchronization primitives are used. Make sure your code does not lock whole classes or whole methods when locking a few lines of code might be appropriate. Also make sure your code does not terminate or pause threads by using Thread.Abort or Thread.Suspend.


5. Boxing
Boxing causes a heap allocation and a memory copy operation. Review your code to
identify areas where implicit boxing occurs. Pay particular attention to code inside loops where the boxing overhead quickly adds up. Avoid passing value types in method parameters that expect a reference type. Sometimes this is unavoidable. In Check List for Improving the Performance of .NET Applications
this case, to reduce the boxing overhead, box your variable once and keep an object reference to the boxed copy as long as needed, and then unbox it when you need a value type again. Excessive boxing often occurs where you use collections that store System.Object types. Consider using an array or a custom-typed collection class instead. To identify locations that might have boxing overhead, you can search your assembly’s Microsoft intermediate language (MSIL) code for the box and unbox instructions, using the following command line.

Ildasm.exe yourcomponent.dll /text | findstr box
Ildasm.exe yourcomponent.dll /text | findstr unbox
To measure the overhead, use a profiler.


For more detailed checklist for managed code performace , visit my blog





Responses

Author: Prasoon Kumar    01 Jul 2009Member Level: Silver   Points : 2
Hi
Explicit Resource Clean Up by calling close or dispose is

necessary when we are dealing with objects in unmanaged

memory like while writing it to log file etc....

otherwise garbage collector will take care of anything

in the managed memory area(managed heap memory).

Regards
Prasoon


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Http://vijirajkumar.blogspot.com/2009/06/check-list-for-improving-performance-of.html  .  

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: Best practices to Improve your .net codes performance
Previous Resource: Passing variables from on form to another in a windows application
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use