<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Folks,<br>
    <br>
    In profiling the code I have been working on, trying to understand
    why it was running very slowly, I have come across what I expect is
    a significant optimisation opportunity. In smokeinvocation.cs, the
    function Invoke starts:<br>
    <br>
    <small><tt>            if (signature.StartsWith("operator==")) {</tt><tt><br>
      </tt><tt>                if (args[1] == null && args[3] ==
        null)</tt><tt><br>
      </tt><tt>                    return true;</tt><tt><br>
      </tt><tt>                else if (args[1] == null || args[3] ==
        null)</tt><tt><br>
      </tt><tt>                    return false;</tt><tt><br>
      </tt><tt>            }</tt><tt><br>
      </tt><tt>            ModuleIndex methodId;</tt><tt><br>
      </tt></small><br>
    If you look into it, the function string.StartsWith is a hugely
    complicated tree of error checks and nested calls, at least 5 levels
    deep, and from what I can tell this call is made for each and every
    smoke-invoked call.<br>
    <br>
    I would suggest, as a minimum, changing it to read:<br>
    <br>
    <small><tt>            if (signature[0] == 'o' &&
        signature.StartsWith("operator==")) {</tt><tt><br>
      </tt><tt>                if (args[1] == null && args[3] ==
        null)</tt><tt><br>
      </tt><tt>                    return true;</tt><tt><br>
      </tt><tt>                else if (args[1] == null || args[3] ==
        null)</tt><tt><br>
      </tt><tt>                    return false;</tt><tt><br>
      </tt><tt>            }</tt><tt><br>
      </tt><tt>            ModuleIndex methodId;</tt><tt><br>
      </tt></small><br>
    so as to limit StartsWith calls to only those with a function name
    starting with an 'o'. Better, in my view, would be to replace
    string.StartsWith (here and possibly elsewhere) with a static
    function:<br>
    <br>
    <small><tt>        public static bool HasPrefix(string str, string
        pfx)<br>
                {<br>
                    if (str.Length < pfx.Length) return false;<br>
                    for (int i = 0; i < pfx.Length; i++)<br>
                    {<br>
                        if (pfx[i] != str[i])<br>
                            return false;<br>
                    }<br>
                    return true;<br>
                }<br>
      </tt></small><br>
    Which should be significantly faster, by dint of not considering
    issues of "culture" and so on. I assume that a null or empty
    "signature" arg is not a situation the code should have to cope with
    gracefully...<br>
    <br>
    <br>
    I do have a question related to this, though: why use literal
    strings for function identification at all? It seems to my limited
    understanding of the subject a very odd choice.<br>
    <br>
    Hope this helps,<br>
    Ruth<br>
    <pre class="moz-signature" cols="72">-- 
Software Manager & Engineer
Tel: 01223 414180
Blog: <a class="moz-txt-link-freetext" href="http://www.ivimey.org/blog">http://www.ivimey.org/blog</a>
LinkedIn: <a class="moz-txt-link-freetext" href="http://uk.linkedin.com/in/ruthivimeycook/">http://uk.linkedin.com/in/ruthivimeycook/</a> </pre>
  </body>
</html>