Posted by Christopher Diggins, 5 September 2012 2:26 pm
I am very interested in C# programming. It is currently my favorite language. One of my favorite parts is LINQ and IEnumerable. It allows me to express powerful algorithms easily and extremely succinctly.
For many of the alogirhtms we write for 3D modeling and animation the IEnumerable interface isn't the best abstraction we could be using. It is extremely general purpose and as a result the performance suffers in certain cases. The most noticeable issues are that random access of elements (IEnumerable.ElementAt()) and retrieving the number of items (IEnumerable.Count()) in an IEnumerable have a worst-case complexity of O(N). In other words, it is very slow, because the implementation requires iterating through all elements in the array.
As a side-project I have been researching how we can improve the performance of collections if we can start from a different set of assumptions. For example, what would happen if we could assume that the underlying collection was arranged sequentially in memory and was immutable, effectively a read-only array.
The first result of my research is a new article on CodeProject called Efficient Map Operations for Arrays in C# that compares the implementation of various implementations of a map higher-order function (also known as IEnumerable.Select() in the C# world).
If you are interested in high-performance C# code check it out!
Please only report comments that are spam or abusive.