Runtime Representation of Generics—Part 2

Tuesday, September 18, 2012

This is an excerpt from Chapter 5 (Collections and Generics) of Pro .NET Performance, scheduled to appear in less than a month. I might be publishing a few more of these before and after the book is out. After giving ample consideration to the design of Java generics and C++ templates, we can understand better the implementation choice for CLR generics. CLR generics are implemented as follows. Generic types — even open ones, like List<> — are first-class runtime citizens. There is a method table and an EEClass for each generic type and a System.Type instance can be...
no comments

Runtime Representation of Generics—Part 1

Monday, August 27, 2012

This is an excerpt from Chapter 5 (Collections and Generics) of Pro .NET Performance, scheduled to appear in less than a month. I might be publishing a few more of these before and after the book is out. Before we can concern ourselves with the runtime implementation of generics, it’s paramount to ask whether there is a runtime representation of generics—as we will see shortly, C++ templates, a similar mechanism, have no runtime representation to speak of. This question is easily answered if you look at the wonders Reflection can do with generic types at runtime: Type...
2 comments

Micro-Benchmarking Done Wrong, And For The Wrong Reasons

Friday, June 22, 2012

This is a short excerpt from Chapter 2 (Performance Measurement) of Pro .NET Performance, scheduled to appear in August 2012. I might be publishing a few more of these before and after the book is out. The purpose is to determine “which is faster”—using the is keyword and then casting to the desired type, or using the as keyword and relying on the result. Here’s a test class for this comparison I’ve seen lately: //Test class class Employee {   public void Work() {} ...

Choosing a Collection Is a Matter of Cache, Too

Thursday, June 7, 2012

This is a short excerpt from Chapter 5 (Collections and Generics) of Pro .NET Performance, scheduled to appear in August 2012. I might be publishing a few more of these before and after the book is out. Choosing the right collection is not only about its performance considerations. The way data are laid out in memory is often more critical to CPU-bound applications than any other criterion, and collections affect this layout greatly. The main factor behind carefully examining data layout in memory is the CPU cache. Modern systems ship with large main memories. Eight GB of...
4 comments

Performance Gains with Data Parallelism: Using SIMD Instructions from C#

Thursday, May 24, 2012

This is a short excerpt (with slight modifications) from Chapter 10 of Pro .NET Performance, scheduled to appear in August 2012. I might be publishing a few more of these before and after the book is out. Theoretically, .NET developers should never be concerned with optimizations tailored to a specific processor or instruction set. After all, the purpose of IL and JIT compilation is to allow managed applications to run on any hardware that has the .NET Framework installed, and to remain indifferent to operating system bitness, processor features, and instruction sets. However, squeezing the last bits of...
5 comments

“Fitting” Performance into the Software Development Lifecycle

Sunday, May 13, 2012

This is a short excerpt from Chapter 1 of Pro .NET Performance, scheduled to appear in August 2012. I might be publishing a few more of these before and after the book is out. We have an Amazon page and a cover image now! Where do you fit performance in the software development lifecycle? This innocent question carries the mind baggage of having to retrofit performance into an existing process. Although it is possible, a healthier approach is to consider every step of the development lifecycle an opportunity to understand the application’s performance better—first, the performance goals and...

Pro .NET Performance

Tuesday, March 13, 2012

It is customary to apologize for a prolonged blog silence, so here goes: I’ve been very busy with three extremely interesting projects, one of which is the SELA Developer Practice that is very near. Here’s another: It’s been more than five years since I wrote a SELA course called Effective C#, which quickly turned to another course called .NET Performance. Since then, I trained this course dozens of times, spoke about performance optimization at conferences, delivered a one-day summary at several tutorials and workshops. All along I was thinking that there is no single decent textbook that combines...