You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bpo-31325: req_rate is a namedtuple type rather than instance
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2017-10-02.10:17:25.436>created_at=<Date2017-10-02.06:14:07.107>labels= ['3.7', 'type-bug', 'library']
title='Issues with request rate in robotparser'updated_at=<Date2017-10-02.10:32:24.614>user='https://github.com/serhiy-storchaka'
First, a new namedtuple type is created for every entry. This is slow even with recent namedtuple optimizations, and is much slower in 3.6. This wastes a memory, since new type is created for every entry. This is definitely wrong, since req_rate is set to a namedtuple type instead of namedtuple instance. And there is a question why a namedtuple is used here at all. Other classes in this module are not namedtuples.
I wasn't aware of the performance implications. Could you please explain to me the type vs instance in terms of performance (or point me to a resource, a quick googling didn't yield anything? How was I supposed to have coded it properly?
Activity
serhiy-storchaka commentedon Oct 2, 2017
There are issues in implementing support of request rate in robotparser.
First, a new namedtuple type is created for every entry. This is slow even with recent namedtuple optimizations, and is much slower in 3.6. This wastes a memory, since new type is created for every entry. This is definitely wrong, since req_rate is set to a namedtuple type instead of namedtuple instance. And there is a question why a namedtuple is used here at all. Other classes in this module are not namedtuples.
XapaJIaMnu commentedon Oct 2, 2017
Hey Serhiy,
The use of namedtuple was requested specifically at a review, I didn't implement it like this initially: https://bugs.python.org/review/16099/#ps6205
I wasn't aware of the performance implications. Could you please explain to me the type vs instance in terms of performance (or point me to a resource, a quick googling didn't yield anything? How was I supposed to have coded it properly?
Cheers,
Nick
serhiy-storchaka commentedon Oct 2, 2017
For the performance of namedtuple type creation see bpo-28638 and https://mail.python.org/pipermail/python-dev/2017-July/148592.html. For difference between types and instance see https://docs.python.org/3/tutorial/classes.html.
berkerpeksag commentedon Oct 2, 2017
Thanks for the report. Your analysis is correct and this is a duplicate of bpo-31325. I'll take care of the PR 3259.
serhiy-storchaka commentedon Oct 2, 2017
Oh, I missed this. My report is based on the same comment on news.ycombinator.com.