[XML-SIG] foo.bar vs. foo.get_bar()

Carey Evans c.evans@clear.net.nz
06 Nov 1999 19:14:23 +1300


"Andrew M. Kuchling" <akuchlin@mems-exchange.org> writes:

> <startled blink> Huh?  Doesn't use them?  Are you sure this is with
> the current version of PyDOM?   It most certainly will not work
> without the __getattr__; the test suite crashes when you try it
> 
> (Internally, though, the code never uses bar attributes like
> .parentNode, calling .get_parentNode() to save the expense of going
> through __getattr__ to call .get_parentNode(), so the stuff in
> dom.core.py might well work without the __getattr__ method.  Callers
> will definitely break, though.)

This is what I meant - even though PyDOM's internal code doesn't need
the __getattr__ method, it's still twice as fast if the method is
removed.

I did some profiling a few months ago, and found that PyDOM spent a
lot of its time recursively calling __getattr__ (via getattr) to find
out whether any get_* or set_* methods existed anywhere in the class
hierarchy for a particular attribute being accessed, and much of the
time there was spent in creating AttributeError object instances.

I guess my point is that I don't want my programs to take twice as
long to run if only one attribute needs to be handled specially, when
accessor functions like the Java bindings are almost as easy to use.
However, it may be that if most access is only getting existing
attributes directly from the object's __dict__, then accessor
functions might be slower, and I'd like to know before deciding which
method I prefer.

-- 
	 Carey Evans  http://home.clear.net.nz/pages/c.evans/

 "Intel's software development efforts ... are directed primarily at
     finding useful ways to consume more microprocessor cycles."