[Interest] QML bindings and redundant property changes

2015-04-01 Thread Preet
Hi all

I want to understand how redundant QML property binding evaluations are
mitigated. Does anyone have a high level idea of how this might be done?

Consider the following case of properties describing a triangle:

Item {
   property real a: 2;
   property real b: 3;
   property real c: Math.sqrt(a*a + b*b);
   property real perimeter: a+b+c;

   onPerimeterChanged: { console.log(perimeter changed); }
}

If you update either 'a' or 'b', onPerimeterChanged will only be called
once. But if you think about the dependencies between the properties, the
perimeter depends on a, b and c:

change a - change perimeter
change a - change c - change perimeter

I would have expected two invocations of onPerimeterChanged, but it gets
called only once. The QML engine avoids the redundant change and I'm
curious as to how this is done.

If you add enough dependencies though, you'll start getting multiple
updates:

Item {
   property real a: 2;
   property real b: 3;
   property real c: Math.sqrt(a*a + b*b);
   property real alt0: a+1;
   property real alt1: alt0+1;
   property real perimeter: a+b+c+alt1;

   onPerimeterChanged: { console.log(perimeter changed); }
}

This will result in onPerimeterChanged being called twice.


Preet
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QML bindings and redundant property changes

2015-04-01 Thread Preet
On Wed, Apr 1, 2015 at 4:57 PM, Daniel França daniel.fra...@gmail.com
wrote:

 For me even your second example calls onPerimeterChanged only once.
 It seems that Qt is smart enough to only notify once when it's evalating
 an expression (that's actually a js function).


That's strange. For me it results in onPerimeterChanged being called twice!
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QML bindings and redundant property changes

2015-04-01 Thread Daniel França
Qt 5.4?

Em qui, 2 de abr de 2015 às 00:03, Preet prismatic.proj...@gmail.com
escreveu:

 On Wed, Apr 1, 2015 at 4:57 PM, Daniel França daniel.fra...@gmail.com
 wrote:

 For me even your second example calls onPerimeterChanged only once.
 It seems that Qt is smart enough to only notify once when it's evalating
 an expression (that's actually a js function).


 That's strange. For me it results in onPerimeterChanged being called twice!
 ___
 Interest mailing list
 Interest@qt-project.org
 http://lists.qt-project.org/mailman/listinfo/interest

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QML bindings and redundant property changes

2015-04-01 Thread Daniel França
For me even your second example calls onPerimeterChanged only once.
It seems that Qt is smart enough to only notify once when it's evalating an
expression (that's actually a js function).


Em qua, 1 de abr de 2015 às 19:12, Preet prismatic.proj...@gmail.com
escreveu:

 Hi all

 I want to understand how redundant QML property binding evaluations are
 mitigated. Does anyone have a high level idea of how this might be done?

 Consider the following case of properties describing a triangle:

 Item {
property real a: 2;
property real b: 3;
property real c: Math.sqrt(a*a + b*b);
property real perimeter: a+b+c;

onPerimeterChanged: { console.log(perimeter changed); }
 }

 If you update either 'a' or 'b', onPerimeterChanged will only be called
 once. But if you think about the dependencies between the properties, the
 perimeter depends on a, b and c:

 change a - change perimeter
 change a - change c - change perimeter

 I would have expected two invocations of onPerimeterChanged, but it gets
 called only once. The QML engine avoids the redundant change and I'm
 curious as to how this is done.

 If you add enough dependencies though, you'll start getting multiple
 updates:

 Item {
property real a: 2;
property real b: 3;
property real c: Math.sqrt(a*a + b*b);
property real alt0: a+1;
property real alt1: alt0+1;
property real perimeter: a+b+c+alt1;

onPerimeterChanged: { console.log(perimeter changed); }
 }

 This will result in onPerimeterChanged being called twice.


 Preet
 ___
 Interest mailing list
 Interest@qt-project.org
 http://lists.qt-project.org/mailman/listinfo/interest

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QML bindings and redundant property changes

2015-04-01 Thread Giuseppe D'Angelo
On 1 April 2015 at 19:11, Preet prismatic.proj...@gmail.com wrote:

 I would have expected two invocations of onPerimeterChanged, but it gets
 called only once. The QML engine avoids the redundant change and I'm curious
 as to how this is done.

http://en.wikipedia.org/wiki/Topological_sorting

-- 
Giuseppe D'Angelo
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QML bindings and redundant property changes

2015-04-01 Thread Giuseppe D'Angelo
Sorry, email sent accidentally. Elaborating: if a changes, the
engine *might* do a topological sorting of a's dependencies to
minimize the number of reevaluations. But I would never ever rely on
such a thing being present and consider it an implementation detail.

On 2 April 2015 at 00:21, Giuseppe D'Angelo dange...@gmail.com wrote:
 On 1 April 2015 at 19:11, Preet prismatic.proj...@gmail.com wrote:

 I would have expected two invocations of onPerimeterChanged, but it gets
 called only once. The QML engine avoids the redundant change and I'm curious
 as to how this is done.

 http://en.wikipedia.org/wiki/Topological_sorting

 --
 Giuseppe D'Angelo



-- 
Giuseppe D'Angelo
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest