Title: __getattribute__ performance on new-style instances should be improved
Type: Severity: normal
Components: Core Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pjenvey Nosy List: leosoto, pjenvey
Priority: normal Keywords:

Created on 2008-08-11.21:42:07 by leosoto, last changed 2009-10-07.02:59:54 by pjenvey.

msg3422 (view) Author: Leonardo Soto (leosoto) Date: 2008-08-11.21:42:05
Currently, almost every lookup on a new-style instance (*Derived) does
in fact two lookups: first finds the '__getattribute__' slot in the type
mro, then the actual attribute lookup takes place. And, if
__getattribute__ raises AttributeError,  another mro lookup takes place,
this time for __getattr__.

This is somewhat solved on old-style instances (PyInstance), where the
__getattr__ slot is cached on PyClass. Although it has a problem: the
cache is not invalidated/refreshed when the __getattr__ slot is
dinamically changed.
msg3424 (view) Author: Leonardo Soto (leosoto) Date: 2008-08-11.22:20:57
We also should take into account that __bases__ can be dynamically
msg5219 (view) Author: Philip Jenvey (pjenvey) Date: 2009-10-06.02:02:06
r6161/r6210 fixed PyClass's cached __xattr__ slots not being refreshed 
when changed
msg5223 (view) Author: Philip Jenvey (pjenvey) Date: 2009-10-07.02:59:53
r6844 / r6845 totally avoid the __getattribute__ lookup/descriptor call 
by fast pathing if the type uses object.__getattribute__. This gives us 
a pretty good speedup, we beat CPython on richards now, @ about .9 
whereas r6843 is about 1.2/3x slower

CPython does an optimization here where it looks up the descriptor and 
fast paths if it's equiv to object.__getattribute__. Our's is based off 
PyPy's which is more agressive, we keeps a flag on the type to determine 
whether we should fast path, so that faster path also avoids the 
descriptor lookup
Date User Action Args
2009-10-07 02:59:54pjenveysetstatus: open -> closed
resolution: fixed
messages: + msg5223
2009-10-06 03:47:34pjenveysetassignee: pjenvey
2009-10-06 02:02:07pjenveysetnosy: + pjenvey
messages: + msg5219
2008-12-17 19:49:24fwierzbickisetpriority: normal
2008-08-11 22:20:58leosotosetmessages: + msg3424
2008-08-11 21:42:07leosotocreate