[motherhamster] vec2d lite

Brian Fisher brian at hamsterrepublic.com
Fri May 4 09:17:32 PDT 2007


On 5/4/07, Bob the Hamster <Bob at hamsterrepublic.com> wrote:
> > Interesting - I'll make a perf test for creating vec2d's. If one of
> > the _lite changes makes that faster, that I'll see about getting those
> > changes in the motherhamster vec2d
>
> I theorized that it was simply a matter of the number of methods and
> properties.
>
Adding properties may take some signficant amount of time, which is
why we uses slots. The slots thing says the instance will never have
any properties other than the ones specified, and in return allocating
the instance and adding the properies is much faster.

The reason why we can add functions that aren't specified in slots is
that we aren't adding the methods as properties to the instance, we're
adding them to the class (the only things added during object creation
are in __init__ and __new__ - there are bound methods, but those get
added by the get method for stuff based on object)

Basically all the class methods get added to the instance in one
operation - when we add the class object to the instance.

So I guess less properties on the class may be faster for property
lookup that falls to the class (although the hash table should make it
usually constant time) or maybe for making bound methods, but it
shouldn't make creating any slower (especially with slots going on)



More information about the Dev mailing list