- Make sure there are indexes available.
- Not too much denormalization. The joins cause performance problems.
- Are triggers causing an insert operation?
- Select only the columns needed.
SQL Performance improvement
May 3rd, 2010Dependency Injection
May 2nd, 2010The dependency injection is a hype in the unit tests world. Some hate it, some love it. The dependency injection is injecting the dependency in a system where the objects are disconnected with loose coupling and require dependency injection to make the system to work. For example, a data retrieval manager can have a data connection object. Before the data retrieval is created, the connection object is created in it’s constructor. This dependency can be broken, and the connection object can be passed as a dependency. That’s what dependency inject is. Now both the connection and manager can be tested separately. There are few ways this injection can be done – constructor injection, setter injection. The third type of injection is through service locater. The service located is a container that creates the objects. This takes the responsibility out of the client to create the objects.
There are few things that are bad about DI. Too much decoupling is bad. The client has to create all the objects for a simple thing to work. The overhead of service locater using the reflector can’t give you an idea of how much time some methods to execute in reality.
.net Dispose Vs Finalize
April 27th, 2010The Dispose Finalize pattern is being used to free the resources in .net. In the C++ world, the resource freeing was deterministic. In .net, it is not. The rule of thumb is to use Dispose to free non-managed resources and Finalize to free managed resources. To use Dispose method, the class has to implement the IDisposable interface. The Dispose method needs to be called explicitly. Normally it is done in using statement. The Finalize is defined like a C++ destructor with ~. The Finalize is expensive and run from different threads by the .net. If Dispose is being called to free a resource, make sure there is a suppress call to Finalize to supress further resource freeing.
Threading in .net
April 26th, 2010There are two ways to create threads in .net. Using the .net threadpool, a thread can be created and run. They are efficient than manually creating a thread and running. It is expensive creating and destroying threads manually. The threadpool manages the thread switching efficiently. The WCF, web services, asp.net web request are all multi threaded apps running in a .net thread pool. The BackgroundWorker helps to create worker thread and run. It is efficient as ThreadPool – Threadpool calls BackgroundWorker to run tasks. This uses events mechanism to queue up functions.
The synchronization can be achieved with Mutex.Start() and Mutex.Stop() critical section objects. The lock() can also be used to protect an area of operation. When locking is used, it is important to lock objects only – locking primitive data items and the lock will create boxes to handle it. Each item a thread is created for a request, boxing happens, and there is no synchronization.
.net memory leakage
April 25th, 2010Is a memory leakage possible in .net? Yes. The unmanages resources should be freed by the application through Dispose. The other situation when a leakage can happen is when the events registered with some object and they are not freed through unregister. Third situation a memory leak can happen is when the collections are not freed before adding again as shown below. It is not necessary to call GC.Collect unless there is heavy usage of memory in an app and should be freed. When the GC.Collect is called, the GC goes through the finalizers of all the objects.
For i = 0 To 1000
da.Fill(DS, "Table" + i.ToString)
Next