-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
very poorly performance on computed property of computed property that accesses a nested array #6660
Comments
This is related and explained in #6284 For now, you can avoid the iteration cost by freezing the Array, if you don't expect it to be mutated. This will no longer be necessary in 3.0 though. |
Wait. This is not the cause. The cause is, that the access to an already computed property is very slow. If you put a watcher between two computed properties, then all is working great. |
@SeregPie Your test is wrong because the watcher is called before it: https://jsfiddle.net/ns1n6kwq/1/ I also added a few tests:
So the results of your test are incorrect and make your think the watcher is called instantly. Also, you are not using The performance issue comes from Vue building the dependencies when evaluating the computed properties: accessing the computed properties multiple times adds even more dependencies and slows down the component. One thing I did when having this kind of performance heavy computed properties was to just access the computed property once and assign it into a local variable: myComputed () {
const a = this.myOtherComputed
// use a instead of this.myOtherComputed
} Example for my proposed solution: https://jsfiddle.net/kLor5ep7/1/ You may find that this is in fact as performant as using a watcher as you can see in this corrected version of your watcher test: https://jsfiddle.net/LrLqmmjr/1/ (The watcher is manually added after the first evaluation of the tl;dr Inside your computed properties, use local variables to store the other computed properties and avoid accessing them directly multiple times. |
Did someone come up with a solution for the use case, when the problem of a slowdown is accessing such computed property in multiple components (instead of having multiple accesses to a computed in another computed) 😅? |
Version
2.4.4
Reproduction link
https://jsfiddle.net/kz16r91L/
Steps to reproduce
First computed property accesses a nested array and second computed property accesses the first computed property.
What is expected?
The computed property is cached and the repeated calls returns the result immediately.
What is actually happening?
The compute function is not called but each access to the computed property is very slow.
Looks like the computed property, that accesses a nested array, is not cached properly.
The text was updated successfully, but these errors were encountered: