Weird performance boost when calling QJSValue aliased property



  • Hello,

    I noticed a strange behavior in Qt, checked on 5.5.1 and 5.7.0 beta. Have a look at the code here. It's a simple example, I have a MyObj class with an overloaded method v: one for reading from and the other one for writing into a QVariantMap. An instance of this class is passed to QJSEngine, which then evaluates body like below and calls this via QJSValue::call 5 million times.

    (function() { obj.v('test1', obj.v('test1') + 0.05); })
    

    The weird thing is that if I do the following:

    QJSValue myObjJS = engine.newQObject(&myObj);
    myObjJS.setProperty("z", myObjJS.property("v"));
    

    And take the following function using this new aliased property:

    (function() { obj.z('test2', obj.z('test2') + 0.05); })
    

    it is noticeably faster, with both Qt 5.5.1 and 5.7.0, debug and release builds:

    ~/projects/builds/qjsperftest-5.5.1%> ./qjsperftest
    Version =  5.5.1
    QVariant(double, 250000)  in  4892  ms
    QVariant(double, 250000)  in  2871  ms
    
    ~/projects/builds/qjsperftest-5.7.0%> ./qjsperftest
    Version =  5.7.0
    QVariant(double, 250000)  in  5907  ms
    QVariant(double, 250000)  in  3514  ms
    
    ~%> gcc --version
    gcc (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413
    

    Any ideas what could be the reason here? I mean, I'm not going to complain having found a faster way to call these methods, but it seems rather weird.

    -- Marcin


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.