We were trying to sort a collection of FileInfo objects in .NET. We implemented our IComparer to ensure that FileInfo objects were sorted based on our criteria. We then noticed that performance of sorting the FileInfo objects was many times slower than just ints. On a hunch (and remembering how references work in C) we were able to improve performance by using local variables to limit the number of times we referenced FileInfo properties.
My idea was that local variables would be faster to access than properties on objects. I think that this makes sense in the world of unmanaged code, where I can actually picture how the stack works and how values are referenced. However, I know the world of managed code can be more complicated under the covers. My question is: Can these basic ideas of memory management and program flow in un-managed code be generally projected into the world of managed code?
Eventually with the help from KeeperOfTheSoul, we were able to track this down to how we were mocking the FileInfo object. For that reason, I have added a RhinoMock tag to this quesiton.