Optimize Qscriptengine Repeated Action
Solution 1:
Why are you creating / initializing a separate QScriptEngine for each iteration? I'd suggest moving everything up to your line
engine.evaluate(jsxmlString);
to outside the for()-loop
.
True, this will make things more difficult WRT threading. Essentially you'd have to set up n worker threads, and create one script engine per thread (not per file). For starters a simple single threaded version should give you a first idea of what speedup to expect, and if that is worth the trouble.
Of course, if your JS code really is single use, only, QScriptProgram
is your only hope of optimization. Again, you'd set up a limited number of worker threads, each with its own QScriptProgram
(and one QScriptEngine
per iteration, as in your current code).
Solution 2:
You can construct a QScriptProgram
, put all JS code in it and evaluate it using QScriptEngine::evaluate
. It could speed up executing because parsing JS code will be done only once. However, QScriptProgram
is not documented as reentrant or thread-safe, so you can't be sure that it will work correctly in multiple threads even if each thread uses its own QScriptProgram
object.
Post a Comment for "Optimize Qscriptengine Repeated Action"