A constraint is dynamically evaluated and this imposes some penalty on performance. Sometimes, you don’t want or don’t need a constraint to be evaluated continuously, but only when your object is initialized. For this, you can use the once keyword. For example, the constraint ${parent.width} in the view in Listing 6.4 is probably only required to be initialized once, because the canvas width never changes throughout its lifetime.
<canvas> <view y="0" bgcolor="0xbbccdd" height="4" width="${parent.width}"> </canvas> |
In this case, you can use once for better performance, as shown in Listing 6.5:
<canvas> <view y="0" bgcolor="0xbbccdd" height="4" width="$once{parent.width}"> </canvas> |
If no keyword is present between $ and {, the value of always is implied. Using once can help your application perform better.