It is said that the designers of WPF have made it economical or higher performance. Can someone please explain with an example of what happens under the hood that makes the WPF property system more economical?
You are probably referring to the fact that Dependency Properties are "cheaper" than normal CLR properties.
In a few words:
Dependency properties are implemented using sparse data structures that only allocate memory for the property value if it is set on an object. In contrast, a standard CLR property value is stored as a field inside every object of the class in which the property is defined, even if all of these objects have the property set to its default value.
So for example, if we have 100 objects with 100 CLR properties of type int
each, then we are using 10000 int
s worth of memory even if all of those have the same default value (0).
If the property were a dependency property instead, we would not be using any additional memory at all: WPF does not need to remember the value of any property since it knows that you didn't change it from the default.
Of course the above is rather a simplistic explanation and does not cover all the advantages of dependency properties over CLR properties, but it should explain the "DPs have higher performance" statement adequately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With