Best practice: value declaration vs using .state directly

Hey there,
as far as I know, there are two ways of using item values in rules: value declaration and using .state directly (see example below).

rule "example"
when 
   Item x changed
then

   val y = item_y.state [as x]
   if (y == 1) {
   <snip>

   if (item_y.state == 1) {
   <snip>

Value declaration might be faster when a value is used multiple times, but the differences were not really measurable on my hardware (Intel NUC with i3-Processor).

Are there any pros and cons about which option to choose? Are there some preferred situations for either ones?

Kind regards!

It’s worth considering what happens if the Item state changes during your rule execution.
Most often the safest course where that might happen is to “capture” the current state in a var= or val= at the head of the rule code.

Use .state so it’s always up to date. There’s absolutely no point in optimizing speed.