Repository navigation
Conversation
|
So far this looks pretty amazing 😊. I will give detailed feedback and discuss stuff later. this might take a while but I'll come back on this ☺ |
| newObserving = null; // during tracking it's array with new observed observers | ||
|
|
||
| isPendingUnobservation: boolean; // for effective unobserving | ||
| isObserved = false; |
There was a problem hiding this comment.
the following invariant if I'm correct? isObserved === dependenciesState !== -1? That might indicate that isObserved might not be explicitly needed?
There was a problem hiding this comment.
It is the case only for ComputedValue.
Atom doesn't implement derivations, so they don't have dependenciesState
Reaction doesn't implement observable so they don't have isObserved.
isObserved is there to make sure that clearing up batch doesn't flip out.
It's kinda safer with.
I am not sure if it's 100% necessary.
|
Left a bunch of comments and notes to self for now, will look later a bit more in depth to a some individual tests and memory and cpu performance in general |
|
Thanks. |
This pull requests rewrites bunch of mobx core to 'change direction' of optimally recalculating changes.
Previously it was propagating from changed observables to observing derivations.
In proposed approach propagated up is only fact that some deep dependency might have changed (and reactions scheduled from it). Derivations before computing itself can check if any dependencies indeed changed and recompute when appropriate.
It introduces few big wins:
autorun(() => a ? b : c)abecomes truecis not being recomputedbatch(() => { ... })would make computed memoized for it's duration, giving (as far as I can tell) minimal possible number of recomputations regardless of modifications or reactions.One issue I had is autoruns rerunning itself. Even though all tests for it are ok, I could point out some corner cases in which behaviour slightly change. In general self-rerunning autoruns, even outside this pull request, have many undefined/unexpected behaviours, although those cases can be quite artificial. I was thinking if we could add a rule so changes in autorun can't schedule it for rerun.
computed temporary memoizationperf test previews the case, that made me do this in the first place.Currently it takes 7 seconds. With changes it's down to ~1ms.
Most perf tests are very similar. Few perform worse.
The nicest thing about it is being able to not compromise clear code with performance even while implementing complex dependencies with possibly expensive actions.
Adjusted few tests, mainly lowering computation count.
Right now pull request doesn't pass the test for whyRun. Need to adjust language to new changes.