QtScript in 4.6
Looking for bars in all the right places
So, is QtScript any faster in 4.6 than in 4.5? As an indicator, I ran the SunSpider benchmark with both versions. Here are the results obtained on my Linux box (longer bars are better; they show speedup over Qt 4.5, so Qt 4.5 results are all 1): Part 1:
It's not always going to be faster.
In order to mitigate this potential issue in the case where you have a small script that you want to run several times, Qt 4.6 comes with a new class called QScriptProgram. QScriptProgram automatically caches the compiled form of your script. This class was added rather late in the 4.6 development and is marked as internal in the 4.6.0 release, so it won't show up in the documentation, but it's there and we think it's safe to start using it... Here's how:
QScriptProgram program("1 + 2");
qDebug() << engine.evaluate(program).toNumber(); // QtScript lazily compiles and executes the program
qDebug() << engine.evaluate(program).toNumber(); // QtScript directly executes the compiled program
We are of course interested in hearing what kind of performance experiences you have with QtScript in 4.6, good or bad.
"I used to have behavioral issues, now I'm feeling better"
Of course, it can't be all roses and peaches. For example, if you've been relying on evaluating nameless function expressions as statements, you should be aware of this quirk that will be present in 4.6.0.
Changes in platform support
Introducing QtScript Classic
Can't live with QtScript gone LGPL? QtScript doesn't build on your platform? Found an (intentional or unintentional) change in QtScript behavior that affects your application when running against Qt 4.6.0? First of all, if your answer is "Yes" to either of the last two questions, we would greatly appreciate it if you report the problem. Second, we are providing the old QtScript back-end as a separate Qt Solution, called QtScript Classic (follow the link for more information and downloads). QtScript Classic can effectively be used to replace the QtScript from 4.6 with the latest from the 4.5 line. Note that Qt 4.6 can be configured with -no-script to avoid building the standard QtScript module. Again, for Tier 2 platforms, if you experience issues with the 4.6.0 release consider trying QtScript Classic.
In Qt 4.6, QtScript should be faster for computation-heavy scripting. It should be more standards-compliant. The C++ API should still behave the same, unless documented otherwise. In short, existing code should mostly continue to work, only faster than before. Please let us know if that's not the case. Reported issues will appear on the QtScript component page in the bug tracker.
Subscribe to our newsletter
Try Qt 6.6 Now!
Download the latest release here: www.qt.io/download.
Qt 6.6. is a feature release with focus on improving UX capabilities including responsive UI technology and the Qt Graph module.
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.