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

前端 未结 4 1159
故里飘歌
故里飘歌 2020-11-29 05:10

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

4条回答
  •  伪装坚强ぢ
    2020-11-29 06:00

    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/

提交回复
热议问题