Hi,
Recently I asked myself such question: what should I recommend to use: DP (Pependency Property) value inheritance or DataBinding?
And my first thoughts were: from one side, DataBinding is much flexible (value can be got from any source and not only from parent) and should have greater performance cost, but from the other side - nothing is said in SDK about it's performance cost while there are a lot of times when DP value inheratance is said to have great performance impact. So I decided to make it clear for myself and proceeded with some test.
Sample was made up of 111110 elements derrived from StackPanel + 1 custom pedendency property.
It took about 300 milliseconds (in avarage) to change the value of the property on the root element.
There was no overhead in memory and in value getting time, all changes were applied immediately. Also there was no overhead in objects initialization time.
Than I checked the same thing with the binding - I disabled value inheritance and added binding to my custom dependency property. Binding was set in constructor, relative source was used to set the element's parent as a source for value. Binding object was created just once, and than reused.
Avarage value setting time was about 10 milliseconds, but it wasn't really updated until the dispatcher processes the queued binding-update messages. So only last change is taken into account. All queue processing takes about 4 seconds. But there is a significant memory overhead in this case - it took 30 more MB to create BinidingExpressions in addition to the 30 MB used to allocate 111111 nodes (and if a new Binding object is created for every binding, than it will take 30 more MB - such behavior can be seen when you declare binding in template).
Some other observation on the binding:
Tree 1
i
-----
i i
--- ---
i i i i
Tree 2
i
--------
i i i i i i
Bindings tree 1 is updated MUCH faster than tree 2, so you should always bind to to your parent and not on the root if you have large hierarchy in logical tree. Example: update of the balanced tree with total 111110 nodes under the root takes 4 seconds while update of 111110 nodes that are under the same parent takes about 10 minutes.
So now you know what does it cost to use inheritance and binding.
Currently rated 5.0 by 1 people
- Currently 5/5 Stars.
- 1
- 2
- 3
- 4
- 5