Threading
- Minimize thread creation.
- Use the thread pool when you need threads.
- Use a Timer to schedule periodic tasks.
- Consider parallel versus synchronous tasks.
- Do not use Thread.Abort to terminate other threads.
- Do not use Thread.Suspend and Thread.Resume to pause threads.
Asynchronous Calls
- Consider client-side asynchronous calls for UI responsiveness.
- Use asynchronous methods on the server for I/O bound operations.
- Avoid asynchronous calls that do not add parallelism.
Locking And Synchronization
- Determine if you need synchronization.
- Determine the approach.
- Determine the scope of your approach.
- Acquire locks late and release them early.
- Avoid locking and synchronization unless required.
- Use granular locks to reduce contention.
- Avoid excessive fine-grained locks.
- Avoid making thread safety the default for your type.
- Use the fine grained lock (C#) statement instead of Synchronized.
- Avoid locking "this".
- Coordinate multiple readers and single writers by using ReaderWriterLock instead of lock.
- Do not lock the type of the objects to provide synchronized access.
Boxing and UnBoxing.
- Avoid frequent boxing and unboxing overhead.
- Measure boxing overhead.
- Use DirectCast in VB.NET code
Exception Management
- Do not use exceptions to control application flow.
- Use validation code to avoid unnecessary exceptions.
- Use the finally block to ensure resources are released.
- Replace VB.NET OnErrorGoTo code with exception handling.
- Do not catch exceptions that you cannot handle.
- Be aware that rethrowing is expensive.
- Preserve as much diagnostic information as possible in your exception handlers.
- Use performance monitor to monitor CLR exceptions.
Iterating and Looping
- Avoid repetitive field or property access.
- Optimize or avoid expensive operations within loops.
- Copy frequently called code into the loop.
- Consider replacing recursion with looping.
- Use for instead of foreach in performance -critical code paths.
Thursday, 27 December 2007
Managed Code Performance, A Checklist - Part 2/3
Posted by VarSHANT at 1:56:00 am
Labels: Performance
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment