[Kde-bindings] Optimisation in smoke method call...

Dimitar Dobrev dpldobrev at yahoo.com
Fri Feb 8 08:52:26 UTC 2013


    

    Hello, Ruth,
    

    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 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.

    Best regards,
    Dimitar   


________________________________
 From: Ruth Ivimey-Cook <ruth at ivimey.org>
To: KDE bindings for other programming languages <kde-bindings at kde.org> 
Sent: Friday, February 8, 2013 2:01 AM
Subject: [Kde-bindings] Optimisation in smoke method call...
 

Folks,

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:

            if (signature.StartsWith("operator==")) {
                if (args[1] == null && args[3] == null)
                    return true;
                else if (args[1] == null || args[3] == null)
                    return false;
            }
            ModuleIndex methodId;

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.

I would suggest, as a minimum, changing it to read:

            if (signature[0] == 'o' && signature.StartsWith("operator==")) {
                if (args[1] == null && args[3] == null)
                    return true;
                else if (args[1] == null || args[3] == null)
                    return false;
            }
            ModuleIndex methodId;

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:

        public static bool HasPrefix(string str, string pfx)
        {
            if (str.Length < pfx.Length) return false;
            for (int i = 0; i < pfx.Length; i++)
            {
                if (pfx[i] != str[i])
                    return false;
            }
            return true;
        }

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...


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.

Hope this helps,
Ruth

-- 
Software Manager & Engineer
Tel: 01223 414180
Blog: http://www.ivimey.org/blog
LinkedIn: http://uk.linkedin.com/in/ruthivimeycook/ 
_______________________________________________
Kde-bindings mailing list
Kde-bindings at kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20130208/4c7fa658/attachment.html>


More information about the Kde-bindings mailing list