Really slow eval() on large data object



  • Hi, I've got a project where I need to download data from service, which returns data in javascript object string, which normally would be evaluated using eval(). I've got no way to change that service - i.e. to return JSON.

    The returned object is ~300kb and need to be evaluated to process it. I've tried using eval() from QML and QJSEngine::evaluate from C++ and it is realllllly slow (~30 seconds). As I understand QMLs eval() uses QJSEngine under the hood, so there is no difference.

    For now the only reasonable solution is to use QScriptEngine::evaluate, which does the parsing almost instantly, but
    as I understand that is the old engine and I don't want an extra dependency/object if QJSEngine is included by default (at least I think so).

    Could this be a QJSEngine bug, or no one really has optimized it for such large objects?
    Another solution would maybe be parsing the response manually, because it contains only array with objects and arrays - so no javascript expressions.



  • Hmmm u can use a man in the middle :) Create a little service with PHP or nodeJS that grab the response from your main service and let your helper service do the heavy work.



  • Thanks for suggestion, but I'm not big fan of hacky approaches and the app will connect directly to end device. It can happen anywhere - even where no public network is available, so that's not a solution.


  • Moderators

    Hi,

    [quote author="chocis" date="1425211151"]For now the only reasonable solution is to use QScriptEngine::evaluate, which does the parsing almost instantly, but
    as I understand that is the old engine and I don't want an extra dependency/object if QJSEngine is included by default (at least I think so).[/quote]It is safe to use QScriptEngine, as it is guaranteed to be supported for the lifetime of Qt 5.x.

    Also, QJSEngine is only included if you use QML.

    [quote author="chocis" date="1425211151"]Could this be a QJSEngine bug, or no one really has optimized it for such large objects?[/quote]I don't know exactly, but I do know that starting with Qt 5.2 QJSEngine uses a custom engine called V4. This engine is optimized for transferring data between C++ and QML, and as a side effect, performance for "pure JavaScript" was reduced compared to the previous engine (V8, which was designed for web browsers)


Log in to reply
 

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