I had an idea tonight which is a variant on inline cachine. V8 (and Self, and others) uses inline caching to accelerate the implementation of x.y . Basically the code generated for a specific x.y in the code is something like:
c = get_hiddden_class(x); if c == cached_class then result = read_slot(x + cached_offset); else offset = lookup_offset(c, "y"); cached_class = c; cached_offset = offset; result = read_slot(x + offset);
Note that the variables cached_class and cached_offset are actually locations in the code (that are patched for the next execution of the code).
The variant of inline caching I came up with has the advantage of not needing to maintain the concept of hidden class. It works directly on hash tables. The idea is to cache the index in the hash table where the last lookup found the property. The next time, the index can be tried first with a test to make sure that the correct property is found:
ht = get_hash_table(x); if cached_index < length(ht) && read_slot(ht + cached_index) == "y" then result = read_slot(ht + cached_index + 1]; else i = hash_table_lookup(ht, "y"); cached_index = i; result = read_slot(ht + i + 1];
The length test could be made faster by combining it with the "modulo" of the table length (which would be a mask if the hash tables always have a length equal to a power of 2).
I would like to try this out to see how well it does.
Marc