How does JavaScript VM implements Object property access? Is it Hashtable?

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

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

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?

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

Answer

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

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..

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

I’m not sure how it works on other VMs

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *