Yesterday I've seen an article about some design principles of V8
JavaScript Engine (http://code.google.com/apis/v8/design.html). In
particular V8 engine optimizes property access using "dynamically
created hidden classes", they are derived when a new property is
created (deleted) on the object.

We would like to suggest a slightly different strategy, which exploits
the cache matches, and does not require a dynamic hidden classes.

Consider an implementation data type with following characteristics:

a) object is implemented as a hash map of property id to property
value: Map<ID, Value>;
b) it stores data as an array of pairs and can be accessed directly:
Pair<ID, Value> values[];
c) property index can be acquired with a method: int index(ID);

A pseudo code for the property access looks like this:

pair = object.values[cachedIndex];

if (pair.ID == propertyID)
{
   value = pair.Value;
}
else
{
  // Cache miss.
  cachedIndex = object.index(propertyID);
  value = objec.values[cachedIndex].Value;
}

This approach brings us back to dictionary like implementation but
with important optimization of array speed access when property index
is cached, and with no dynamic hidden classes.

See also 
http://www.nesterovsky-bros.com/weblog/2011/12/17/FastPropertyAccessInV8JavaScriptEngine.aspx
--
Vladimir Nesterovsky

-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users

Reply via email to