Tag vs Expression Binding

If an expression binding is only referencing a tag via {pathToTag}, instead of using a "Tag" type binding, is there any real difference, other than the icon that appears next to the component?

A different code path is used, though ultimately the thing that's managing the subscription will be a tag change listener.

I would expect a 'native' tag binding to offer slightly better performance than an expression binding; probably basically identical once setup but a little bit faster to start up initially.

So, I guess the logical next question is, which is better. An expression tag and then a tag binding, or just an expression binding? I would guess the former

Depends how many times you need the calculation in the expression and how complex it is.

In terms of maintenance, which is definitely going to be a more important factor here, I'd definitely prefer the expression tag, since it'll be much easier to change if you ever need to update the expression.

Yes, there is one huge difference: expression bindings must deliver an answer within the execution thread of the binding. This is particularly important in Vision, where this happens on the single UI thread.

Proper tag bindings, including any indirect bindings, do not have to deliver an immediate value--they can wait until the value is available and deliver asynchronously.

You should always use tag bindings instead of expressions with a tag reference.

5 Likes

Along those lines, for style customers, I often create a custom property that is the result of an expression. But I create custom properties also and bind the tags directly to those properties, and then use the properties in the expression. So the expression doesn't have any direct tags, but properties that have direct tag bindings. Is that any better, worse, etc? It makes it so all my widgets are consistent and maintenance is much easier.

Yes, this is best.

2 Likes

I think it's a good idea to come up with a standard within your company for where you put custom properties to handle indirect bindings efficiently so everyone knows where to look when supporting other people's work.

If I am building a screen or popup that's evaluating information from multiple tags in the same expression I create a custom property for each binding and populate it with an indirect binding. Then my expressions evaluate property references to those custom properties. Another advantage is that you can see live values for what the expression is evaluating if you're troubleshooting something. I especially like how this works out in perspective because of how properties are organized.

I believe this is what @pturmel is saying is optimal so correct me if I'm wrong.

2 Likes