Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(reactivity): better computed tracking #710

Merged
merged 1 commit into from
Feb 9, 2020

Conversation

jods4
Copy link
Contributor

@jods4 jods4 commented Feb 9, 2020

I made computed use track and trigger directly.

Why?

  • Code is shorter and simpler. trackChildRun depended on activeEffect and was basically a copy of tracking internals. The new code is straightforward to understand: it simply calls track when value is read.
  • Debugging is more clear. If you look at dependencies during debugging, you'll see the computed, rather than what's cached behind.
  • It's more efficient. If the getter depends on hundreds of values (typical use case: computed filters or summarizes an array), those 100+ dependencies will be registered on the computed effect, but then transitively copied as dependencies of any effect that reads the computed. With N dependencies and M readers, before PR we had N*(M+1) entries, after PR N+M.
    Not only does it save space, it also saves time if many dependencies change at once. If N dependencies change at once, the number function calls is the same as the entries above (after PR, computed only calls trigger once, rather than having a notification for every dependency that changes).

@yyx990803 yyx990803 merged commit 8874b21 into vuejs:master Feb 9, 2020
@yyx990803
Copy link
Member

👍 This is indeed better, thanks!

@jods4 jods4 deleted the computed-track branch February 9, 2020 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants