On 9/4/08, Martin Probst <[EMAIL PROTECTED]> wrote:
>
>  Hi,
>
>
>  > My understanding of this optimization in V8 is that it's laser-
>  > targeted
>  > at probably the biggest bottleneck of Javascript: property lookup.
>
>
> Excuse my curiosity, but my basic understanding of this optimization
>  is like this: in JS, you don't have classes, so every object is
>  potentially completely different from all others. Therefore, you'd
>  always need to make the hash lookup when something says "foo.bar", as
>  everything foo might be is always different. Thus creating these
>  "hidden classes" allows you to classify sets of similar "foo" things,
>  so that you can cache the meaning of "bar" (i.e. offset from object
>  pointer) for these classes, I think this is called polymorphic inline
>  caching?


As well as the comic there's this description
http://code.google.com/apis/v8/design.html

As I understand it each object is an instance of a "hidden class" and
contains a reference to that class. If an object's structure is
mutated by adding a property then a new class, which is a subclass of
the original class, is created and replaces the "hidden class"
reference in the object. The effect of this is that in a normal
program you will have very many objects which share the same class.

The code generated for property access first tests to see if the
hidden class is the class it expects. If it is the code falls through
to instructions which implement the property access directly. If it
does not a call is made to the runtime system which rewrites the
generated code to use the new hidden class and this new code is then
executed.

This seems fast and simple. It would not be hard to write code which
continuously forced code rewriting but I think it's highly unlikely
you would commonly encounter such code in real world systems.

The fact that Javascript does not support threads considerably
simplifies the situation.

John Wilson

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to jvm-languages@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to