This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Change module attribute get & set
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: gvanrossum, tim.peters
Priority: normal Keywords: patch

Created on 2001-05-11 09:11 by tim.peters, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
modpatch.txt tim.peters, 2001-05-11 09:11
Messages (6)
msg36571 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2001-05-11 09:11
Module objects currently don't define the tp_getattro 
or tp_setattro slots.  As a result, interning of 
attribute names does them no good:  a char* is always 
passed, so the dict lookup always needs to do a string 
compare despite that the attribute name is interned.

The patch simply implements these slots, and nulls out 
the raw-string tp_getattr and tp_setattr slots.

The former is by far the more important one, and I've 
measured speedups over 25% for simple programs that do 
lots of module lookups inside loops (random.random, 
os.path, etc).

So, sure looks like a big cheap win to me, but 
assigning for review in case I'm missing something 
obvious (i.e., if it's such an easy win, why didn't we 
already do it?).
msg36572 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-05-11 13:35
Logged In: YES 
user_id=6380

There's no deep reason -- this code is ancient and has never
drawn anybody's attention.  I noticed the same thing while
doing a review of getattr vs. getattro for the descr-branch
code.

So I'd say, go for it!
msg36573 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-05-11 14:23
Logged In: YES 
user_id=6380

BTW, by convention the C function's name changes to
..._getattro and ..._setattro.
msg36574 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2001-05-11 21:27
Logged In: YES 
user_id=31435

(getattrofunc)class_getattr, /* tp_getattro */
(getattrofunc)instance_getattr,	/* tp_getattro */
(getattrofunc)instancemethod_getattro,	/* tp_getattro */
(getattrofunc)func_getattro, /* tp_getattro */
(getattrofunc)proxy_getattr, /*tp_getattro*/
(getattrofunc)proxy_getattr,/*tp_getattro*/

It's not much of a convention when only 2 of 6 existing 
slots followed it!  Pronounce, please (make it 2 of 7, 3 of 
7, or change the non-conformers too to make it 7 of 7).
msg36575 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-05-11 21:30
Logged In: YES 
user_id=6380

Oh, fudge.  It *should* be a convention.

But I don't care, this code won't be needed in the
descr-branch anyway.
msg36576 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2001-05-11 21:53
Logged In: YES 
user_id=31435

OK, I made it 3 of 7 then.  Checked in as

Objects/moduleobject, new revision: 2.32
Misc/NEWS, new revision: 1.165
History
Date User Action Args
2022-04-10 16:04:03adminsetgithub: 34494
2001-05-11 09:11:40tim.peterscreate