tink_state icon indicating copy to clipboard operation
tink_state copied to clipboard

early break in AutoObservable s.hasChanged check can trigger multiple recalculations

Open nadako opened this issue 2 years ago • 2 comments

I've found an interesting thing while porting your excellent library to C#. When AutoObservable checks if any of the subscriptions has actually changed it breaks earlier and skips checking other dependencies, which sounds logical... However hasChanged in the current revision also updates the revision and value for a Subscription, and if we only do that for the first changed dependency and skip all other, the subsValid will return false and we'll need a second loop iteration.

At first I was thinking that the correct fix would be to simply remove break here, however after some investigation, I think it's even better to update Subscription.lastRev on reuse. What do you think?

https://github.com/haxetink/tink_state/blob/58eacef024117290ebe060401e0b894681415226/src/tink/state/internal/AutoObservable.hx#L255

nadako avatar Nov 21 '22 13:11 nadako

Ok. I think I sorta understand what you're saying. But you wouldn't happen to have a failing test for the current behavior? ^^

back2dos avatar Apr 26 '23 07:04 back2dos

If I remember correctly it doesn't exactly fail in a sense of broken state or invalid values, but it does unnecessary loops.

nadako avatar Apr 26 '23 07:04 nadako