[Mono-list] Performance / array access
Miguel de Icaza
miguel@ximian.com
12 Jan 2003 21:22:10 -0500
Hello,
> 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 = 0; i < array.Length; ++i)
> sum += array [i];
>
> But not here:
>
> int len = array.Length;
> for (int i = 0; i < len; ++i)
> sum += 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 ;-)
This is a very good observation. Because it seems that this particular
kind of loop is detected by the JIT engine.
Array-bounds-check elimination is something we want to do with the new
JIT, but it is not implemented at this point. The new JIT features a
new intermediate representation that simplifies implementing this sort
of thing, but it is still on its bootstrapping phases of life.
Miguel