Martin Probst wrote:
> Now when you have a class based language like Python or Ruby, you  
> already have these sets of similar things where the same property  
> names resolve to the same things (the classes). I.e. if your "foo.bar"  
> statements gets hit with foo being a specific instance, you can see if  
> you cache contains the resolved location of bar for this class. Ruby  
> has this "eigenclass" exception, but that's probably a rare case.
> 
> So, I wonder how this optimization will help Ruby/Python/any class  
> based, dynamic language? Am I missing something?

Python uses "slots" heavily, and many optimizations in Python impls seek 
to optimize access to those slots. Method invocation is not just 
"dispatch to this method", it's "lookup whatever's in this slot and 
invoke it like a method". I believe local variables are also technically 
slot-based, which makes it much similar to JS in that regard. So the 
same optimizations done for JS in V8 could directly apply to Python for 
sure.

In Ruby's case, most really critical things are not slots. Methods can 
only be defined as methods and have their own lookup/dispatch process 
which can be optimized as a result. Local variables are determined at 
parse time, and only evals--which in Ruby 1.8 share a lexically-scoped 
"binding scope"--can actually cause new variables to come into existence 
(and then only in the binding scope, so only other evals can see them). 
Where we have more dynamic behavior is in constant and instance variable 
lookup. Constants are both lexically and hierarchically scoped to the 
containing class object, which means that thousands of constants can be 
visible to a given piece of code due to it having to walk both lexical 
containers and superclasses to find them. An optimization to speed 
lookup of those constants, avoiding O(n) searching, could be adapted out 
of the V8 techniques. Instance variables, on the other hand, are an open 
hash on each object instance, and new variables can be added at any time 
by any class in the object's class hierarchy or via a few methods 
accessible from outside the object. So programs that make heavy use of 
instance variables end up spending a lot of time doing hash lookups, and 
a V8 optimization to specialize ivar tables as they stabilize could 
improve this code as well.

- Charlie

--~--~---------~--~----~------------~-------~--~----~
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