Bug 3814 - Calling value type over generic type parameter is slow
Summary: Calling value type over generic type parameter is slow
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-03-08 12:28 UTC by Marek Safar
Modified: 2012-03-12 20:11 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Marek Safar 2012-03-08 12:28:24 UTC
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
    interface IA
    {
        void Method();
    }

    struct S : IA
    {
        public void Method()
        {
        }
    }

    struct SG
    {
        public void Test<T>(ref T t) where T : IA
        {
            t.Method();
        }
    }

	class Program
	{
		static void Main (string[] args)
		{
			S s;
            var sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < 100000000; ++i)
            {
                s = new S ();
                new SG().Test(ref s);
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);            
			Console.WriteLine (s);
			return;
		}
	}
}

on amd64

Mono: 620
.NET: 52
Comment 1 Zoltan Varga 2012-03-10 13:42:46 UTC
This has nothing to do with calling valuetypes, the mono JIT inlines everything into a tight loop, while the MS JIT realizes that the loop doesn't do anything and eliminates it altogether.
Comment 2 Marek Safar 2012-03-12 08:24:22 UTC
That's not the case. Increasing loop number count by 10 fold increases the time by 10 fold for .NET

from 52 to 551
Comment 3 Zoltan Varga 2012-03-12 11:06:30 UTC
The loop doesn't do anything, MS is just better at removing this nothingness than we are.
Comment 4 Zoltan Varga 2012-03-12 20:11:05 UTC
-O=all now reduces this to 71 from 462, and running with the LLVM backend reduces it to 1.