[Mono-list] mono performance, 20x differential with Java (what am i doing wrong)

Miguel de Icaza miguel at novell.com
Fri Jan 29 13:43:01 EST 2010


Hello Jonathan,

    We were recently investigating some work on this area and there are
a couple of things that you can do to improve the execution speed for
computationally intensive code:

	* Compile Mono using the LLVM backend, I strongly recommend
	  that you use Mono from SVN where a lot of new LLVM integration
	  work has taken place.

	* Our Arrays-bounds-check elimination code is not as strong
	  as it could be.    One thing that you can do, for tasks that
	  will take days to run, and where you know that you will not
	  get an out-of-range exception is to remove from the
	  runtime arrays bounds checking.

    I recently did both of those, and it results in a 4x performance
improvement in SciMark and matches Java's performance.

    Mono needs more work in the area of arrays bounds checking
elimination as the above is not really a production solution (removing
the ABC checks from the runtime).   But it should be useful for those
that need this today.

    Get this patch:

	http://tirania.org/tmp/bounds-check-elim.diff

    Then build Mono with LLVM:

	http://www.mono-project.com/Mono_LLVM

    It will get you a 4x perf boost (the patch is for x86-64, if you are
in another platform you will need to remove the equivalent code).
Perhaps an interim solution is for us to add a -O=noboundscheck.


> Hi,
> 
> 
> I'm quite familiar with both the .NET and Java development
> environments, but only recently have begun to experiment with mono, so
> forgive me if I'm not clued-in.   
> 
> 
> I specialize in numerical work that often involves a lot large-scale
> array manipulation for linear algebra, timeseries, etc.    My main
> production platforms are OSX and Linux.   I've been doing most of my
> work on the JVM over the past few years, though spent a couple of
> years with .NET when it was pre-release / pre-1.0.  
> 
> 
> My main interest is in Ocaml, particularly the F# variant as the basis
> for my numerical work.
> 
> 
> One of the first things I do when considering a platform is run
> benchmarks, as performance is critical for what I do.    Starting with
> C# I wrote a test to gauge the array-access overhead associated with
> the platform.  Without knowing how to tweak the mono runtime to turn
> on any particular optimisations, the results were quite poor for this
> specific test (see code at the end of this posting).
> 
> 
> 
> 
> The test on my MacPro 2.6 Ghz / Snow Leopard with mono 2.6.1 gave the
> result of:
> 
> 
> 16 sec, 130 ms for 1000 iterations
> 
> 
> the same code, modified just for IO, etc on the Java VM (without
> -server)  gave a runtime of:
> 
> 
>  0 sec, 831 ms
> 
> 
> changing the # of iterations to higher amounts did nothing to improve
> the ratio.   Java is 20x faster in this benchmark.
> 
> 
> I could not find any documentation concerning settings for the
> -optimize flag on the mono VM, so perhaps there is a setting I should
> be using.   
> 
> 
> Secondly, I saw the posting concerning the optional use of LLVM.  I
> have not been able to build mono on OSX as am having problems building
> glib.  I'm wondering whether anyone has a packaged up version of glib
> or better a packaged up version of mono with LLVM enabled.
> 
> 
> I have heard only good things about LLVM performance, so hoping that
> this will help address this gap.   Hopefully I am doing something
> wrong here and the performance is much closer.   Test code below ...
> 
> 
> regards
> 
> 
> Jonathan
> --
> http://tr8dr.wordpress.com/
> 
> 
> 
> 
> using System;
> 
> 
> namespace Performance
> {
> 
> 
> public class ArrayTest
> {
> 
> public static double test1 (double[] vec)
> {
> double sum = 0;
> for (int i = 8 ; i < vec.Length ; i++)
> {
> vec[i] = 2*vec[i] - vec[i-1];
> for (int j = 1 ; j < 8 ; j++)
> sum += 1.3 * vec[j-1];
> }
> 
> return sum;
> }
> 
> 
> public static void Main (string[] argv)
> {
> int iterations = argv.Length > 0 ? int.Parse(argv[0]) : 1000;
> 
> double[] vec = new double[100000];
> for (int i = 0 ; i < vec.Length ; i++)
> vec[i] = i;
> 
> DateTime Tstart = DateTime.Now;
> Console.WriteLine ("starting performance test on " + iterations + "
> iterations");
> 
> double sum = 0;
> for (int i = 0 ; i < iterations ; i++)
> sum += test1 (vec);
> 
> DateTime Tend = DateTime.Now;
> TimeSpan Tspan = Tend - Tstart;
> Console.WriteLine ("ending performance test on " + iterations + "
> iterations, time: " + Tspan.Seconds + ":" + Tspan.Milliseconds);
> 
> 
> Console.WriteLine ("result: " + sum);
> }
> }
> }
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list




More information about the Mono-list mailing list