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): cache source.length to len, Reduce once Accessing #7830

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

zhangenming
Copy link
Contributor

@zhangenming zhangenming commented Mar 5, 2023

commit 1
source In most cases, it's one proxy
Accessing the length attribute is expensive
it will triggers getter and track

commit 2
Not sure if it's necessary

@zhangenming
Copy link
Contributor Author

zhangenming commented Mar 5, 2023

这里应该有个优化点, 不知道是否有必要实现
考虑 ret[i] = renderItem(source[i], i, void 0, cached && cached[i]);
是不是可以改成ret[i] = renderItem(source, i, void 0, cached && cached[i]);
或者其他形式

目的是为了减少不必要的source[i]访问
当cache命中的时候
source[i]是没有必要求值的
这样可以减少大部分proxy带来的消耗
我这个场景下 额外的成本还是挺高的 如下图
这里的renderList里的get成本都是source[i]带来的 而大部分都是cache过的
image

@zhangenming
Copy link
Contributor Author

@chatgpt translate

translate

Copy link
Member

@haoqunjiang haoqunjiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有必要重构掉 new Array。在已知数组长度的情况下,new Array(len) 的性能是高于逐个填充数组元素的。

至于缓存 source.length 的性能提升,是否有更进一步的性能数据(比如 trace.json 文件)?

@haoqunjiang haoqunjiang added the 🧹 p1-chore Priority 1: this doesn't change code behavior. label May 29, 2024
@edison1105 edison1105 added the need more info Further information is requested label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 p1-chore Priority 1: this doesn't change code behavior. need more info Further information is requested
Projects
Status: Waiting
Development

Successfully merging this pull request may close these issues.

3 participants