Slow performance using getter references other getter
See original GitHub issueVersion
3.1.2
Reproduction link
https://jsfiddle.net/tbetous/y4m0keav/53/
Steps to reproduce
1 - Write a getter myGetter
that use another getter otherGetter
by using getters
argument
myGetter: (state, getters) => {
console.time('myGetter')
const t0 = performance.now();
for(let i = 0; i < 100; i ) {
const foo = getters.otherGetter
}
console.timeEnd('myGetter')
const t1 = performance.now();
return t1 - t0
},
2 - Write a getter myGetterOptimized
that use another getter otherGetter
by destructuring getters
myGetterOptimized: (state, {otherGetter}) => {
console.time('myGetterOptimized')
const t0 = performance.now();
for(let i = 0; i < 100; i ) {
const foo = otherGetter
}
console.timeEnd('myGetterOptimized')
const t1 = performance.now();
return t1 - t0
},
3 - Compare time execution
What is expected?
Time execution should be the same.
What is actually happening?
Time execution is different :
- getterOptimized : 0.21999999989930075
- getterNotOptimized : 494.8850000000675
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
c++ - Getters and Setters. Is there performance overhead?
Setters and getters have a performance overhead when not optimized out. They are almost always optimized out on compilers that do link time...
Read more >782913 - Using property getters/setters is dramatically slower ...
Using property getters/setters is dramatically slower than calling the getters/setters directly.
Read more >Effective Dart: Design
When a member produces a result without any side effects, it should usually be a getter or a method with a noun phrase...
Read more >direct access vs. setter-getter performance - Community
Getters and setters are essentially sugar-coated wrappers for methods. So it's going to be slower than directly accessing something. Moreover, ...
Read more >Getters And Setters In Java: Common Mistakes, And ... - Xperti
Mistake 2: Assigning object references directly in the setter. Mistake 3: Returning the object reference directly in the getter. Mistake 4: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks a lot @kiaking ! You answered to my question ! I guess I can close the issue.
@cuebit If we track the getter’s calculation, we find that it’s calculated only once no matter if called in a cycle or before the cycle. https://jsfiddle.net/kasheftin/9oh3svn2/ - here’s the slightly updated version, where getter calc included into timeline. It shows the same difference. I would say that the real reason of this huge difference is that any vuex getter provides a Proxy, calling the getter requests Proxy.get method, and the last has some inner logic like dependency tracking.