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

V8是如何提升对象访问速度 #45

Open
jinzhepro opened this issue Apr 23, 2023 · 0 comments
Open

V8是如何提升对象访问速度 #45

jinzhepro opened this issue Apr 23, 2023 · 0 comments

Comments

@jinzhepro
Copy link
Owner

常规属性(properties)和排序属性(element)

对象中的字符串属性被称为properties,是按照创建的顺序;数字属性被称为element,按照索引值大小排序。

af2654db3d3a2e0b9a9eaa25e862cc75-1024x759

在对象bar内部分别使用了两个线性数据结构保存这两种属性,索引顺序element → properties

对象内属性

为了提升查找效率,V8实现了对象内属性策略,如果对象属性少于一定数量时,V8就会把这些属性直接写入对象中。如果多于一定数量时,V8就会将线性存储模式降级为非线性字典结构,这样虽然降低了查找速度,但是提升了修改速度。

数量少时

WX20210114-100258

数量多时

WX20210114-100337

隐藏类Map

描述了对象内的属性布局,包括对象名和偏移量,每次对象的修改都会更新隐藏类。

守护隐藏类

  • 初始化保持顺序一致
  • 一次性初始化完毕
  • 谨慎使用delete,破坏隐藏类增加额外的查找速度。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant