Tribal Knowledge: Large Object Heap and Double Arrays in .Net

In the .Net world when objects are greater than 85 thousand bytes they are generally placed in the Large Object Heap (LOH). But there is a caveat to that and certain objects are placed in the LOH way before 85K. The one situation I detail here in this blog is the double array which goes in way sooner.

It appears that because of performance issues, it is better to insert the double arrays earlier due to the fact that the LOH is aligned in 8 byte increments. This allows better access to those large arrays in normal code processing and the tradeoff point was 1 thousand doubles and was implemented in .Net that way.

That is my piece of Tribal Knowledge that I pass on to you…use it wisely.

Recently I got a chance to explore why this had not changed for .Net 4 and the realm of 64 bit computing when I was at the Microsoft Campus talking to some of the people on the CLR team. One of the Senior Project Managers who works with the CLR team at Microsoft Andrew Pardoe was kind enough to provide this clarification that things are still the same for .Net 4 and 64 bit applications for arrays of 1000 doubles; but that may change going forward:

The CLR’s execution engine aggressively attempts to place these arrays on the LOH because of the performance benefit of accessing aligned doubles. However, there’s no benefit to applying this heuristic on 64-bit architectures because doubles are already aligned on an 8-byte boundary.

Thank you for bringing this to my attention. We’ve made changes to this heuristic that should appear in a future release of the .NET Framework.