JavaScript VM 如何实现 Object 属性访问?它是哈希表吗? [英] How does JavaScript VM implements Object property access? Is it Hashtable?

查看:19
本文介绍了JavaScript VM 如何实现 Object 属性访问?它是哈希表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript 中的对象可以用作 Hashtable(键必须是字符串)数据结构是否和Hashtable一样好?

Objects in JavaScript can be used as Hashtable (the key must be String) Is it perform well as Hashtable the data structure?

我的意思是,它是否在幕后实现为 Hashtable?

I mean , does it implemented as Hashtable behind the scene?

更新:(1)我将 HashMap 更改为哈希表(2)我猜大多数浏览器都实现了它,如果不是为什么不呢?在 ECMAScript 规范中是否有任何要求如何实现它?

Update: (1) I changed HashMap to hashtable (2) I guess most of the browser implement it the same, if not why not? is there any requirement how to implement it in the ECMAScript specs?

更新 2:我明白了,我只是想知道 V8 和 Firefox JS VM 是如何实现 Object.properties getter/setter 的?

Update 2 : I understand, I just wonder how V8 and the Firefox JS VM implements the Object.properties getters/setters?

推荐答案

V8 没有将对象属性访问实现为哈希表,它实际上以更好的方式实现它(性能方面)

V8 doesn't implement Object properties access as hashtable, it actually implement it in a better way (performance wise)

那么它是如何工作的呢?V8 不使用动态查找来访问属性.相反,V8 在幕后动态创建隐藏类"——这使得访问属性的速度几乎与访问 C++ 对象的属性一样快.

So how does it work? "V8 does not use dynamic lookup to access properties. Instead, V8 dynamically creates hidden classes behind the scenes" - that make the access to properties almost as fast as accessing properties of C++ objects.

为什么?因为在固定类中,每个属性都可以在特定的固定偏移位置上找到..

Why? because in fixed class each property can be found on a specific fixed offset location..

所以通常在 V8 中访问对象的属性比 Hashtable 更快..

So in general accessing property of an object in V8 is faster than Hashtable..

我不确定它在其他虚拟机上是如何工作的

I'm not sure how it works on other VMs

更多信息可以在这里找到:https://developers.google.com/v8/design#prop_access

More info can be found here: https://developers.google.com/v8/design#prop_access

您还可以在此处阅读有关 JS 中 Hashtable 的更多信息:(我的博客)http://simplenotions.wordpress.com/2011/07/05/javascript-hashtable/

You can also read more regarding Hashtable in JS here:(my blog) http://simplenotions.wordpress.com/2011/07/05/javascript-hashtable/

这篇关于JavaScript VM 如何实现 Object 属性访问?它是哈希表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆