Why is performance better in a LinkedList when a reference type value and its node are created at the same time?

Viewed 377

This questions stems from the MSDN page on LinkedList under "Remarks" (fifth line).

Lists that contain reference types perform better when a node and its value are created at the same time. LinkedList accepts null as a valid Value property for reference types and allows duplicate values.

I have searched through the source code and nothing really stands out to me. Could it be that this line was once true but was just forgotten about? If not, then why is it the case?

1 Answers

My guess is that it has to do with Locality of reference.

.NET uses a compressing garbage collector, that means that in case of reference type values, those would be allocated alongside its related LinkedListNode<T> in the actual RAM region. If you access the value right after reaching the node, there is a good chance the value is already in cache.

Related