C# Performance tips
Recently I completed reading CLR via C# by Jeffrey Richter and I really recommend every C# programmer to at least read it once. I really learned how exactly .NET framework works and how exactly can we improve the performance. Today I will share some of the tips which I read it in the book. And tips are totally from genius Jeffrey Richter.
One of the thing which I learnt was that always declare the Class as Sealed if its not going to inherit. In fact author always suggested to always declare the class as Sealed by default. Performance wise calling a virtual method doesn’t perform as well as calling a non-virtual method because the CLR must look up the type of the object at runtime in order to determine which type defines the method to call. And if JIT compiler sees a call to virtual method whose Class is sealed, JIT compiler produces the efficient code compared to the on-sealed class.
Problem with the sealed class is, its bit inconvenience since every time I need to type. But performance overshadows the inconvenience. I hope you’ll like this performance tip. Please share if you any of such performance tip.