tink_state
tink_state copied to clipboard
early break in AutoObservable s.hasChanged check can trigger multiple recalculations
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
Ok. I think I sorta understand what you're saying. But you wouldn't happen to have a failing test for the current behavior? ^^
If I remember correctly it doesn't exactly fail in a sense of broken state or invalid values, but it does unnecessary loops.