Hi Jonathan,<div><br></div><div>There are a few factors that affect inlining. </div><div><br></div><div>We don't inline more than 10 levels deep, but I doubt this is your problem.</div><div>We don't inline synchronized methods, methods that belong to MarshalByRef classes or method that do exception handlibg. Not your case, probably.</div>
<div>We only inline methods smaller than 20bytes of IL. It might be your case. You can control this with the MONO_INLINELIMIT env var or use the AgressiveInlining compiler hint.</div><div>We don't inline calls to classes that need their class constructor to be ran. Might be your case.</div>
<div>We don't do inlining when generics are involved. Doesn't look to be your case;</div><div>And, finally, we don't inline methods that call other methods (including constructors).</div><div><br></div><div>The last restriction does look to be your issue. We do it due to a pair of issues, first because it produces broken stacktraces</div>
<div>and because it breaks calls that check caller assembly. Both can be fixed if mono had support for inlining maps.</div><div><br></div><div>My suggestion is that you play with MONO_INLINELIMIT and AgressiveInlining. This can be reported as a feature request.</div>
<div>I would love to see this done.</div><div><br></div><div>Regards,</div><div>Rodrigo</div><div><br></div><div><div class="gmail_quote">On Sat, Jul 14, 2012 at 9:36 PM, Jonathan Shore <span dir="ltr"><<a href="mailto:jonathan.shore@gmail.com" target="_blank">jonathan.shore@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>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.</div>
<div><br></div><div>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:</div><div><br></div><div>
<span style="white-space:pre-wrap">     </span>class SpecialVector : Vector<double></div><div><span style="white-space:pre-wrap">       </span>{</div><div><span style="white-space:pre-wrap">                </span>...</div><div><span style="white-space:pre-wrap">              </span>public override double this[int i]</div>
<div><span style="white-space:pre-wrap">          </span>{</div><div><span style="white-space:pre-wrap">                        </span>get { return _data[i]; }</div><div><span style="white-space:pre-wrap">                 </span>set { _data[i] = value; }</div><div>
<span style="white-space:pre-wrap">             </span>}</div><div><br></div><div><span style="white-space:pre-wrap">               </span>public override double[] Data</div><div><span style="white-space:pre-wrap">                    </span>{ get { return _data; } }</div>
<div><br></div><div><span style="white-space:pre-wrap">         </span>...</div><div><br></div><div><span style="white-space:pre-wrap">             </span>private double[] _data;</div><div><span style="white-space:pre-wrap">  </span>}</div>
<div><br></div><div><br></div><div>I have a rather tight-looped numerical algorithm on a number of these vectors.  Such as:</div><div><br></div><div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco">
<font color="#113afc"><div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px"><span style="color:rgb(17,58,252)"><span style="white-space:pre-wrap"> </span>for</span> (<span style="color:rgb(17,58,252)">int</span> i = <span style="color:rgb(187,75,211)">0</span> ; i < len ; i++)</div>
<div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px"><span style="white-space:pre-wrap">  </span>{</div><div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px">
<span style="white-space:pre-wrap">             </span><span style="color:rgb(17,58,252)">var</span> x = x[i];</div><div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px">
<span style="white-space:pre-wrap">             </span>...</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;color:rgb(106,162,24);font-family:Helvetica;font-size:medium">
<span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">              </span><span style="color:rgb(17,58,252)">for</span> (<span style="color:rgb(17,58,252)">int</span> k = ileft; k <= iright; k++) </span></div><div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px">
<span style="white-space:pre-wrap">             </span>{</div><div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px"><span style="white-space:pre-wrap">                        </span><span style="color:rgb(17,58,252)">var</span> xk = x[k];</div>
<div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px"><span style="white-space:pre-wrap">                  </span><span style="color:rgb(17,58,252)">var</span> yk = y[k];</div>
<div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px"><span style="white-space:pre-wrap">                  </span>..</div><div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px">
<span style="white-space:pre-wrap">             </span>}</div><div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px"><span style="white-space:pre-wrap">                </span>...</div>
<div style="margin-right:0px;font:normal normal normal 11px/normal Monaco;font-size:medium;margin-left:0px;margin-bottom:0px;font-family:Helvetica;margin-top:0px;min-height:15px"><span style="white-space:pre-wrap">  </span>}</div>
<div><br></div></font></div></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;min-height:15px"><span style="font-family:Helvetica;font-size:medium">Where,  <b>x</b> and <b>y</b> are instances of these vectors.   x[i] and y[i] call the this[int] accessor on their respective vectors.   <b>Vector<double></b> defines <b>double this[int i]</b> as a virtual function.   </span></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;min-height:15px"><span style="font-family:Helvetica;font-size:medium"><b><br></b></span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;min-height:15px">
<span style="font-family:Helvetica;font-size:medium"><b>SpecialVector</b> is a sealed class, however.   Nevertheless, I realize a 25% increase in performance if I do the following:</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;min-height:15px">
<span style="font-family:Helvetica;font-size:medium"><br></span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;min-height:15px"><font face="Helvetica" size="3"><span style="white-space:pre-wrap">       </span><b>var vx = x.Data;</b></font></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;min-height:15px"><font face="Helvetica" size="3"><span style="white-space:pre-wrap">       </span><b>var vy = y.Data;</b></font></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;min-height:15px"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;font-family:Helvetica;font-size:medium">
<span style="color:rgb(17,58,252)"><span style="white-space:pre-wrap">  </span>for</span> (<span style="color:rgb(17,58,252)">int</span> i = <span style="color:rgb(187,75,211)">0</span> ; i < len ; i++)</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;font-family:Helvetica;font-size:medium">
<span style="white-space:pre-wrap">     </span>{</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;font-family:Helvetica;font-size:medium"><span style="white-space:pre-wrap">                </span><span style="color:rgb(17,58,252)">var</span> x = <b>vx</b>[i];</div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;font-family:Helvetica;font-size:medium"><span style="white-space:pre-wrap">          </span>...</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;color:rgb(106,162,24);font-family:Helvetica;font-size:medium">
<span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">              </span><span style="color:rgb(17,58,252)">for</span> (<span style="color:rgb(17,58,252)">int</span> k = ileft; k <= iright; k++) </span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;font-family:Helvetica;font-size:medium">
<span style="white-space:pre-wrap">             </span>{</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;font-family:Helvetica;font-size:medium"><span style="white-space:pre-wrap">                        </span><span style="color:rgb(17,58,252)">var</span> xk = <b>vx</b>[k];</div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;font-family:Helvetica;font-size:medium"><span style="white-space:pre-wrap">                  </span><span style="color:rgb(17,58,252)">var</span> yk = <b>vy</b>[k];</div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;font-family:Helvetica;font-size:medium"><span style="white-space:pre-wrap">                  </span>..</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;font-family:Helvetica;font-size:medium">
<span style="white-space:pre-wrap">             </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;font-family:Helvetica;font-size:medium"><span style="white-space:pre-wrap">                </span>...</div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font:normal normal normal 11px/normal Monaco;min-height:15px;font-family:Helvetica;font-size:medium"><span style="white-space:pre-wrap">  </span>}</div>
<div><br></div><div><span style="font-family:Helvetica;font-size:medium">I suspect that mono / LLVM is not attempting inline <b>this[int i] </b>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?</span></div>
<div><span style="font-family:Helvetica;font-size:medium"><br></span></div><div><span style="font-family:Helvetica;font-size:medium">Should this be reported as a bug or feature request?  </span></div><div><span style="font-family:Helvetica;font-size:medium"><br>
</span></div><div><span style="font-family:Helvetica;font-size:medium">Thanks</span></div><span class="HOEnZb"><font color="#888888"><div><span style="font-family:Helvetica;font-size:medium"><br></span></div><div><span style="font-family:Helvetica;font-size:medium">Jonathan</span></div>
</font></span></div></div><br>_______________________________________________<br>
Mono-devel-list mailing list<br>
<a href="mailto:Mono-devel-list@lists.ximian.com">Mono-devel-list@lists.ximian.com</a><br>
<a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" target="_blank">http://lists.ximian.com/mailman/listinfo/mono-devel-list</a><br>
<br></blockquote></div><br></div>