<html>
<head>
</head>
<body class='hmmessage'><div dir='ltr'>

<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style>
<div dir="ltr"><div>> Date: Wed, 10 Jun 2015 21:33:44 +1200<br>> From: robertc@robertcollins.net<br>> To: openstack-dev@lists.openstack.org<br>> Subject: Re: [openstack-dev] [all][python3] use of six.iteritems()<br>> <br>> On 10 June 2015 at 17:22, gordon chung <gord@live.ca> wrote:<br>> > maybe the suggestion should be "don't blindly apply six.iteritems or items" rather than don't apply iteritems at all. admittedly, it's a massive eyesore, but it's a very real use case that some projects deal with large data results and to enforce the latter policy can have negative effects[1].  one "million item dictionary" might be negligible but in a multi-user, multi-* environment that can have a significant impact on the amount memory required to store everything.<br>> <br>> > [1] disclaimer: i have no real world results but i assume memory management was the reason for the switch in logic from py2 to py3<br>> <br>> I wouldn't make that assumption.<br>> <br>> And no, memory isn't an issue. If you have a million item dict,<br>> ignoring the internal overheads, the dict needs 1 million object<br>> pointers. The size of a list with those pointers in it is 1M (pointer<br>> size in bytes). E.g. 4M or 8M. Nothing to worry about given the<br>> footprint of such a program :)</div><div><br></div><div>iiuc, items() (in py2) will create a copy of  the dictionary in memory to be processed. this is useful for cases such as concurrency where you want to ensure consistency but doing a quick test i noticed a massive spike in memory usage between items() and iteritems.</div><div><br></div><div>'for i in dict(enumerate(range(1000000))).items(): pass' consumes significantly more memory than 'for i in dict(enumerate(range(1000000))).iteritems(): pass'. on my system, the difference in memory consumption was double when using items() vs iteritems() and the cpu util was significantly more as well... let me know if there's anything that stands out as inaccurate.</div><div><br></div><div>unless there's something wrong with my ignorant testing above, i think it's something projects should consider when mass applying any iteritems/items patch.</div><div><br></div><div><span style="font-size: 12pt;">cheers,</span></div><div><span style="font-size: 12pt;">gord</span></div></div>
                                          </div></body>
</html>