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

前端 未结 4 1141
故里飘歌
故里飘歌 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:02

    this article explains how they are implemented in V8, the engine used by Node.js and most versions of Google Chrome

    https://v8.dev/blog/fast-properties

    apparently the "tactic" can change over time, depending on the number of properties, going from an array of named values to a dictionary.

    v8 also takes the type into account, a number or string will not be treated in the same way as an object (or function, a type of object)

    if i understand this correctly a property access frequently, for example in a loop, will be cached.

    v8 optimises code on the fly by observing what its actually doing, and how often

    v8 will identify the objects with the same set of named properties, added in the same order (like a class constructor would do, or a repetitive bit of JSON, and handle them in the same way.

    see the article for more details, then apply at google for a job :)

提交回复
热议问题