-
Notifications
You must be signed in to change notification settings - Fork 248
Do not call reaction functions with stale values #1113
Comments
Should we even be batching reaction functions at all? |
Separating reaction functions out makes it easier to understand their cost within the digest loop. We originally made this change to be most consistent with object.observe. |
@naomiblack There may be other ways to understand the cost. e.g. #1119 (UserTags) |
@jbdeboer is it possible that TC39 had actual good reasons to avoid passing the current value to listeners? Maybe it's the right thing to do. I'm interested in reading their notes on it, but I haven't been able to find discussions on that yet. If something is too big of a performance or complexity hit for the platform, maybe it stands to reason that it doesn't make much sense in Angular, either |
I think that this issue should be renamed to something more generic. Like "Separating dirty-checks and reactions functions results in doing extra work" The issues that we see are:
|
@tbosch identified this issue in Angular 2.0 / watchtower.js.
Since we batch reaction functions, we may be calling reaction functions with stale values. This leads to unnecessary digests, or in the worst case, infinite (bounded by TTL) loops.
Instead, during the reaction phase, immediately before calling the reaction function, we should recompute the value. If the value has changed back to the old value, do not call the reaction function.
As part of this change, we should add an intermediate "assert" change which counts the number of times this situation occurs. We can run this assert in apps to understand the impact of this change.
cc @mhevery
The text was updated successfully, but these errors were encountered: