Python from Wise Guy's Viewpoint

Pascal Costanza costanza at web.de
Wed Oct 29 09:46:05 EST 2003


Fergus Henderson wrote:
> Pascal Costanza <costanza at web.de> writes:
> 
> 
>>Fergus Henderson wrote:
>>
>>
>>>Pascal Costanza <costanza at web.de> writes:
>>
>>>>Well, the research that ultimately lead to the HotSpot Virtual Machine 
>>>>originated in virtual machines for Smalltalk and for Self. Especially 
>>>>Self is an "extremely" dynamic language, but they still managed to make 
>>>>it execute reasonably fast.
>>>
>>>Please correct me if I'm wrong, but as I understand it, iterating over a
>>>collection of values is still going to require keeping some representation
>>>of the type of each element around at runtime, and testing the type for
>>>each element accessed, in case it is not the expected type.  AFAIK neither
>>>HotSpot nor the Self compiler do the kind of optimizations which would
>>>be needed to avoid that.
>>
>>You don't need to check the type on each access. If you only copy a 
>>value from one place to other, and both places are untyped, you don't 
>>need any check at all.
> 
> 
> Great.  I feel so much better now.  Now my type errors are free to
> propagate throughout my program's data structures, so that when they
> are finally detected, it may be far from the true source of the problem.

Now, you have changed the topic from optimization to catching errors 
again. Could you please focus what you want to talk about?

And guess what, "in 99% of all cases, such type errors don't occur in 
practice, at least not in my eperience". ;-P (Sorry, couldn't resist. I 
sincerely hope you read this as a joke, and not as an attack. ;)

> But the example that I was thinking of did actually want to access the
> value, not just copy it.
> 
>>Furthermore, if I remember correctly, dynamically compiled systems use 
>>type inferencing at runtime to reduce the number of type checks.
> 
> In cases such as the one described above, they may reduce the number of
> times that the type of the _collection_ is checked, but they won't be
> able to avoid checking the element type at every element access.

Why? If the collection happens to contain only elements of a single type 
(or this type at most), you only need to check write accesses if they 
violate this condition. As long as they don't, you don't need to check 
read accesses.

"In 99% of all cases, write accesses occur rarely, at least ..." - well, 
you know the game. ;)


Pascal

-- 
Pascal Costanza               University of Bonn
mailto:costanza at web.de        Institute of Computer Science III
http://www.pascalcostanza.de  Römerstr. 164, D-53117 Bonn (Germany)





More information about the Python-list mailing list