[Mono-list] Performance / array access

Piers Haken piersh@friskit.com
Sun, 12 Jan 2003 15:40:45 -0800


This is a multi-part message in MIME format.

------_=_NextPart_001_01C2BA94.06ECD74A
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Yeah, Microsoft's JIT lifts invariant bounds-checks. But I believe it's
pretty limited.

For example, the check is removed in the following case:

  for (int i =3D 0; i < array.Length; ++i)
    sum +=3D array [i];

But not here:

  int len =3D array.Length;
  for (int i =3D 0; i < len; ++i)
    sum +=3D array [i];

So the first case is (counter-intuitively) faster than the second.

I don't believe Mono's JIT makes this optimization. Maybe the new JIT
will ;-)

Piers.

> -----Original Message-----
> From: Tom Fransen [mailto:t.fransen@mailned.nl]=20
> Sent: Sunday, January 12, 2003 10:12 AM
> To: Mono-list@ximian.com
> Subject: [Mono-list] Performance / array access
>=20
>=20
> Hi everybody,
>=20
> I am looking into the performance of both the Microsoft .NET=20
> Framework and Mono. What I found is that the Microsoft code=20
> for bubble sort runs a lot faster
> (3x)
> than the Mono code. Looking further into the problem I found=20
> that when compiling a assembly with the switch 'optimize for=20
> speed' (on
> Windows)
> the JIT optimization is enabled via some attribute in the=20
> assembly. Look at the assembly code that is generated I saw=20
> that in case of optimized code there is no longer a check (at=20
> least not within the for loop) that checks if the index used=20
> to store items in the array is within the required bounds.
>=20
> I case of Mono I see (if I interpret this correctly) that=20
> within the for loop each array index is checked to see if it=20
> is within bounds.
>=20
> Here are my questions
> a) Is my observation (for Mono) correct?
>=20
> b) Is this something that still needs to be implemented in=20
> the Mono JIT compiler or do I need to enable some setting for=20
> this optimization?
>=20
> Can anybody comment on this.
>=20
> regards,
> Tom
>=20
>=20
> _______________________________________________
> Mono-list maillist  -  Mono-list@ximian.com=20
> http://lists.ximian.com/mailman/listinfo/mono-list
>=20

------_=_NextPart_001_01C2BA94.06ECD74A
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.0.4417.0">
<TITLE>RE: [Mono-list] Performance / array access</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=3D2>Yeah, Microsoft's JIT lifts invariant bounds-checks. =
But I believe it's pretty limited.</FONT>
</P>

<P><FONT SIZE=3D2>For example, the check is removed in the following =
case:</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; for (int i =3D 0; i &lt; array.Length; =
++i)</FONT>

<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; sum +=3D array [i];</FONT>
</P>

<P><FONT SIZE=3D2>But not here:</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; int len =3D array.Length;</FONT>

<BR><FONT SIZE=3D2>&nbsp; for (int i =3D 0; i &lt; len; ++i)</FONT>

<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; sum +=3D array [i];</FONT>
</P>

<P><FONT SIZE=3D2>So the first case is (counter-intuitively) faster than =
the second.</FONT>
</P>

<P><FONT SIZE=3D2>I don't believe Mono's JIT makes this optimization. =
Maybe the new JIT will ;-)</FONT>
</P>

<P><FONT SIZE=3D2>Piers.</FONT>
</P>

<P><FONT SIZE=3D2>&gt; -----Original Message-----</FONT>

<BR><FONT SIZE=3D2>&gt; From: Tom Fransen [<A =
HREF=3D"mailto:t.fransen@mailned.nl">mailto:t.fransen@mailned.nl</A>] =
</FONT>

<BR><FONT SIZE=3D2>&gt; Sent: Sunday, January 12, 2003 10:12 AM</FONT>

<BR><FONT SIZE=3D2>&gt; To: Mono-list@ximian.com</FONT>

<BR><FONT SIZE=3D2>&gt; Subject: [Mono-list] Performance / array =
access</FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>

<BR><FONT SIZE=3D2>&gt; Hi everybody,</FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>

<BR><FONT SIZE=3D2>&gt; I am looking into the performance of both the =
Microsoft .NET </FONT>

<BR><FONT SIZE=3D2>&gt; Framework and Mono. What I found is that the =
Microsoft code </FONT>

<BR><FONT SIZE=3D2>&gt; for bubble sort runs a lot faster</FONT>

<BR><FONT SIZE=3D2>&gt; (3x)</FONT>

<BR><FONT SIZE=3D2>&gt; than the Mono code. Looking further into the =
problem I found </FONT>

<BR><FONT SIZE=3D2>&gt; that when compiling a assembly with the switch =
'optimize for </FONT>

<BR><FONT SIZE=3D2>&gt; speed' (on</FONT>

<BR><FONT SIZE=3D2>&gt; Windows)</FONT>

<BR><FONT SIZE=3D2>&gt; the JIT optimization is enabled via some =
attribute in the </FONT>

<BR><FONT SIZE=3D2>&gt; assembly. Look at the assembly code that is =
generated I saw </FONT>

<BR><FONT SIZE=3D2>&gt; that in case of optimized code there is no =
longer a check (at </FONT>

<BR><FONT SIZE=3D2>&gt; least not within the for loop) that checks if =
the index used </FONT>

<BR><FONT SIZE=3D2>&gt; to store items in the array is within the =
required bounds.</FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>

<BR><FONT SIZE=3D2>&gt; I case of Mono I see (if I interpret this =
correctly) that </FONT>

<BR><FONT SIZE=3D2>&gt; within the for loop each array index is checked =
to see if it </FONT>

<BR><FONT SIZE=3D2>&gt; is within bounds.</FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>

<BR><FONT SIZE=3D2>&gt; Here are my questions</FONT>

<BR><FONT SIZE=3D2>&gt; a) Is my observation (for Mono) correct?</FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>

<BR><FONT SIZE=3D2>&gt; b) Is this something that still needs to be =
implemented in </FONT>

<BR><FONT SIZE=3D2>&gt; the Mono JIT compiler or do I need to enable =
some setting for </FONT>

<BR><FONT SIZE=3D2>&gt; this optimization?</FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>

<BR><FONT SIZE=3D2>&gt; Can anybody comment on this.</FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>

<BR><FONT SIZE=3D2>&gt; regards,</FONT>

<BR><FONT SIZE=3D2>&gt; Tom</FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>

<BR><FONT SIZE=3D2>&gt; =
_______________________________________________</FONT>

<BR><FONT SIZE=3D2>&gt; Mono-list maillist&nbsp; -&nbsp; =
Mono-list@ximian.com </FONT>

<BR><FONT SIZE=3D2>&gt; <A =
HREF=3D"http://lists.ximian.com/mailman/listinfo/mono-list">http://lists.=
ximian.com/mailman/listinfo/mono-list</A></FONT>

<BR><FONT SIZE=3D2>&gt; </FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C2BA94.06ECD74A--