Hello Peter,

> 4. We can reach better performance with "with" if we use function inside
> "with":
> with(o) (function() { for(var i = 0; i < 1000000; ++i) Math.sin(i); })()
> time: 221msec
>
> The fourth example just a suggestion to using "with" statement and reach
> better performace without modify the JS engine.
> Would it be possible to use the latest form for your purposes?

We might be confusing things here. I'll give a sketch of how the
bindings are created and evaluated, imagine this snippet of QML

MyItem {
   prop: valueA + valueB + Math.sin(0)
}

what the engine currently does is (you can checkout
src/declarative/qdeclarativeexpression.cpp for more detais)

1) push a "clean" context (which is a function context in JS terms),
pushContext() from qtscript API
2) create an object that represents the context of the expression,
this object is from a special scriptclass that will perform lookup in
the properties of the object and other things QML provide.
3) create an object that mimics the global object (has Math, etc).

Then both objects (2) and (3) are pushed as scopes (which are with
contexts in JS terms), the original expression is rewritten as a
function:

(function() { valueA + valueB + Math.sin(0) })

and evaluated, the value is stored and the clean context is popped.

An _approximation_ in JS of what we do would be:

(function() { // this is the "clean" context
  var context = Engine.createDeclarativeContextForObject(obj);
  var newGlobal = Engine.getStaticGlobalObject();

  with (context) {
    with (newGlobal) {
      return (function() { valueA + valueB + Math.sin(0) });
    }
  }
})(); // we evaluate, store the value and close the "clean" context

The returned value is a function, when executed will give us the value
of the expression. QML re-executes it when it knows some dependency
changed.

So this is the way that works right now. We get the repeated execution
of the "whole package". Are there ways to improve things in this
scenario?

Our static global object is "static" (has a fixed set of properties),
could that information do improve lookup speed when inside with()
contexts?


Last month I posted to the list that there's an edge case in Web that
a similar dynamic behavior is necessary, and they implement it in a
very similar fashion but without C++ APIs. Maybe this can give some
insight, or help understanding our case better.

http://thread.gmane.org/gmane.comp.lang.javascript.v8.general/3738/focus=3743

the actual code / comments are in this file:

http://trac.webkit.org/browser/trunk/Source/WebCore/bindings/v8/V8LazyEventListener.cpp


Cheers,

-- 
Caio Marcelo de Oliveira Filho
OpenBossa - INdT
_______________________________________________
Qt-script mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-script

Reply via email to