Hi guys,
since we have to speed up with statements. we have investigated the
following example mentioned by Kent before:
with ($item) {
with ($child) {
(function() { return foo + 1; })() // this is the anonymous
// function QML generates for the binding expression "foo + 1"
}
}
To our surprise, it turned out that the resolving of 'foo' happened
during the function creation, and not when you actually call it.
See the next example:
a = { x:5 }
b = { x:8 }
x = 1
with (a) {
with (b) {
c = function() { print(x) }
}
}
c()
Here, the calling of 'c' yields '8', although it is outside the with
statement. This gives us an interesting optimization opportunity as
seen in the next example:
var t = new Date()
with (a) {
c = function() { x }
}
for (var i = 0; i < 10000000; ++i)
c()
print(new Date() - t) // 2238 ms
var t = new Date()
for (var i = 0; i < 10000000; ++i)
with (a) {
(function() { x })()
}
print(new Date() - t) // 4619 ms
The two function calls do the same thing, but the first one is more
than twice as fast. Therefore creating the function before the loop is
much faster. Would it be possible to generate your code in that way?
If not, we need to focus on speeding up function creation (resolving
variables), and not the with statement itself.
There was another 'simple' test:
o = {};
for (var i = 0; i < 1000000; ++i) {
with (o) // uncomment to get optimal performance
Math.sin(i);
}
Note, that this 'simple' test does not cover the original example,
even if we were able to speed this up, you would not get a faster
execution for Qml!
We have three questions:
- Can you move out the function creations from the loop statements?
- If not, shall we work on optimizing the function creations?
- Is the last example still an important use case, or it was intended
to be an example?
Regards,
Szeged Team
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
_______________________________________________
Qt-script mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-script