Frequently Asked Questions about Expressions

How can I improve the performance of my expressions when they contain a large number of sibling nodes?

Expressions with logic around siblings like Node.Siblings.Any(SiblingNode.Properties.Boolean Prop) can cause performance issues in hierarchies where there are a lot of siblings. This is because each node has a unique set of siblings. For example, for a top node with children A, B, C, D, and E, node A has siblings B,C,D,E, node B has siblings A,C,D,E, etc.

A better way to construct the expression is to create a property that you will reference on the parent using the children and then referencing that property on the node. For example, you can create a property called ChildrenBooleanSet with expression Node.Children.Any(ChildNode.Properties.Boolean Prop), and then reference that property on the node: Node.Parent.Properties.ChildrenBooleanSet.

This type of expression results in better performance because the parent value can be cached.

Caution:

Be aware that with the example expression above, the children will include the node itself and the siblings do not. You can add extra logic to filter out the node itself if needed.