[Mono-dev] mono / llvm inlining situations (or failures thereof)

Jonathan Shore jonathan.shore at gmail.com
Sun Jul 15 00:36:51 UTC 2012


I have a significant # of numerical routines that make use of vectors, matrices, etc.   I have observed that mono --llvm does seem not inline access in some situations where it reasonably could.   This means for a difference in performance of about 25% in my code.

I am using a 3rd party library for vector / matrix functionality that has a generic class  Vector<T>.   I have created a number of specializations of this class, such as:

	class SpecialVector : Vector<double>
	{
		...
		public override double this[int i]
		{
			get { return _data[i]; }
			set { _data[i] = value; }
		}

		public override double[] Data
			{ get { return _data; } }

		...

		private double[] _data;
	}


I have a rather tight-looped numerical algorithm on a number of these vectors.  Such as:

	for (int i = 0 ; i < len ; i++)
	{
		var x = x[i];
		...
		for (int k = ileft; k <= iright; k++) 
		{
			var xk = x[k];
			var yk = y[k];
			..
		}
		...
	}

Where,  x and y are instances of these vectors.   x[i] and y[i] call the this[int] accessor on their respective vectors.   Vector<double> defines double this[int i] as a virtual function.   

SpecialVector is a sealed class, however.   Nevertheless, I realize a 25% increase in performance if I do the following:

	var vx = x.Data;
	var vy = y.Data;
	for (int i = 0 ; i < len ; i++)
	{
		var x = vx[i];
		...
		for (int k = ileft; k <= iright; k++) 
		{
			var xk = vx[k];
			var yk = vy[k];
			..
		}
		...
	}

I suspect that mono / LLVM is not attempting inline this[int i] since is a virtual method, in spite of being trivially determined to be leaf class.  OR is there another reason why this is not inlined?

Should this be reported as a bug or feature request?  

Thanks

Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120714/4ae022f0/attachment-0001.html>


More information about the Mono-devel-list mailing list