[openstack-dev] [all][python3] use of six.iteritems()
Jay Pipes
jaypipes at gmail.com
Wed Sep 14 04:17:29 UTC 2016
On 09/13/2016 08:23 PM, Terry Wilson wrote:
> On Tue, Sep 13, 2016 at 6:31 PM, Jay Pipes <jaypipes at gmail.com> wrote:
>> On 09/13/2016 01:40 PM, Terry Wilson wrote:
>>>
>>> On Thu, Jun 11, 2015 at 8:33 AM, Sean Dague <sean at dague.net> wrote:
>>>>
>>>> On 06/11/2015 09:02 AM, Jay Pipes wrote:
>>>>>
>>>>> On 06/11/2015 01:16 AM, Robert Collins wrote:
>>>>>>
>>>>>> But again - where in OpenStack does this matter the slightest?
>>>>>
>>>>>
>>>>> Precisely. I can't think of a single case where we are iterating over
>>>>> anywhere near the number of dictionary items that we would see any
>>>>> impact whatsoever.
>>>
>>>
>>> In neutron, the ovsdb native code iterates over fairly large
>>> dictionaries since the underlying OVS library stores OVSDB tables
>>> completely in memory as dicts. I just looked at the code I wrote and
>>> it currently uses values() and I now want to switch it to
>>> six.itervalues() :p.
>>>
>>>>> Best,
>>>>> -jay
>>>>
>>>>
>>>> +1.
>>>>
>>>> This is a massive premature optimization which just makes all the code
>>>> gorpy for no real reason.
>>>
>>>
>>> Premature optimization is about wasting a bunch of time trying to
>>> optimize code before you know you need to, not about following the
>>> accepted almost-always-faster/always-less-memory-using solution that
>>> already exists. Memory-wise it's the difference between a constant
>>> 88-byte iterator and the storage for an additional list of tuples. And
>>> if Raymond Hettinger, in a talk called "Transforming Code Into
>>> Beautiful Idiomatic Python" specifically mentions that people should
>>> always use iteritems
>>> (https://www.youtube.com/watch?v=OSGv2VnC0go&feature=youtu.be&t=21m24s),
>>> I tend to believe him. Sure, it'd be much better if Python 3 and
>>> Python 2 both returned iterators for items(), values(), keys(), etc.,
>>> but it doesn't. Wasting memory for purely aesthetic reasons (they're
>>> even both the same number of lines) is just a bad idea, IMNSHO.
>>
>>
>> Is it wasted time to respond to a mailing list post from 18 months ago?
>>
>> -jay
>
> Ha! Absolutely it is. Someone posted a Neutron patch haphazardly
> converting all of of the six.iteritems() calls to items() and it
> struck a nerve. I searched for the thread in gmail not noticing the
> date. My apologies! :)
Heh, no worries, I was mostly just being tongue-in-cheek :)
-jay
More information about the OpenStack-dev
mailing list