<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><span class="tab"> <br></span><div><span class="tab"> Hello, Ruth,</span><br><span class="tab"> <br></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span class="tab"> Thank you about your observation. The solution would be actually to delete this code as I already generate it for == and != operators, that is, at compile time. This was a recent change - when </span>I fixed the QRect != null crash. I'll delete this piece and push it as soon as I'm done with the readSettings crash (as I've written in my mail to you from last night). But I had no idea this slows it down so much so once again, thank you for your work.</div><div style="color: rgb(0,
0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span class="tab"><br></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span class="tab"> Best regards,</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span class="tab"> Dimitar</span><span class="tab"> </span></div><div><br></div> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1"> <b><span style="font-weight:bold;">From:</span></b> Ruth Ivimey-Cook
<ruth@ivimey.org><br> <b><span style="font-weight: bold;">To:</span></b> KDE bindings for other programming languages <kde-bindings@kde.org> <br> <b><span style="font-weight: bold;">Sent:</span></b> Friday, February 8, 2013 2:01 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> [Kde-bindings] Optimisation in smoke method call...<br> </font> </div> <br>
<div id="yiv2116725115">
<div>
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 <a target="_blank" href="http://smokeinvocation.cs/">smokeinvocation.cs</a>, 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="yiv2116725115moz-signature">--
Software Manager & Engineer
Tel: 01223 414180
Blog: http://www.ivimey.org/blog
LinkedIn: http://uk.linkedin.com/in/ruthivimeycook/ </pre>
</div>
</div><br>_______________________________________________<br>Kde-bindings mailing list<br><a ymailto="mailto:Kde-bindings@kde.org" href="mailto:Kde-bindings@kde.org">Kde-bindings@kde.org</a><br><a href="https://mail.kde.org/mailman/listinfo/kde-bindings" target="_blank">https://mail.kde.org/mailman/listinfo/kde-bindings</a><br><br><br> </div> </div> </div></body></html>