Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29938 > unrolled thread

Memory usage per top 10x usage per heapy

Started byMrsEntity <junkshops@gmail.com>
First post2012-09-24 14:59 -0700
Last post2012-09-25 18:35 -0500
Articles 2 on this page of 22 — 10 participants

Back to article view | Back to comp.lang.python


Contents

  Memory usage per top 10x usage per heapy MrsEntity <junkshops@gmail.com> - 2012-09-24 14:59 -0700
    Re: Memory usage per top 10x usage per heapy Tim Chase <python.list@tim.thechases.com> - 2012-09-24 18:22 -0500
    Re: Memory usage per top 10x usage per heapy Junkshops <junkshops@gmail.com> - 2012-09-24 16:58 -0700
      Re: Memory usage per top 10x usage per heapy bryanjugglercryptographer@yahoo.com - 2012-09-27 01:00 -0700
      Re: Memory usage per top 10x usage per heapy bryanjugglercryptographer@yahoo.com - 2012-09-27 01:00 -0700
    Re: Memory usage per top 10x usage per heapy Dave Angel <d@davea.name> - 2012-09-24 21:14 -0400
    Re: Memory usage per top 10x usage per heapy Junkshops <junkshops@gmail.com> - 2012-09-24 21:21 -0700
    Re: Memory usage per top 10x usage per heapy Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-25 00:41 -0400
    Re: Memory usage per top 10x usage per heapy Tim Chase <python.list@tim.thechases.com> - 2012-09-25 05:51 -0500
    Re: Memory usage per top 10x usage per heapy Dave Angel <d@davea.name> - 2012-09-25 07:06 -0400
    Re: Memory usage per top 10x usage per heapy Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-25 12:10 +0100
    Re: gracious responses (was: Memory usage per top 10x usage per heapy) Tim Chase <python.list@tim.thechases.com> - 2012-09-25 06:40 -0500
      Re: gracious responses (was: Memory usage per top 10x usage per heapy) alex23 <wuwei23@gmail.com> - 2012-09-25 05:44 -0700
        Re: gracious responses Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-25 13:53 +0100
    Re: gracious responses Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-25 12:54 +0100
      Re: gracious responses Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-25 15:17 +0000
    Re: Memory usage per top 10x usage per heapy Dave Angel <d@davea.name> - 2012-09-25 14:50 -0400
    Re: Memory usage per top 10x usage per heapy Junkshops <junkshops@gmail.com> - 2012-09-25 14:02 -0700
    Re: Memory usage per top 10x usage per heapy Junkshops <junkshops@gmail.com> - 2012-09-25 14:35 -0700
    Re: Memory usage per top 10x usage per heapy Tim Chase <python.list@tim.thechases.com> - 2012-09-25 17:10 -0500
    Re: Memory usage per top 10x usage per heapy Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-25 16:09 -0600
    Re: Memory usage per top 10x usage per heapy Tim Chase <python.list@tim.thechases.com> - 2012-09-25 18:35 -0500

Page 2 of 2 — ← Prev page 1 [2]


#30130

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-09-25 16:09 -0600
Message-ID<mailman.1381.1348611003.27098.python-list@python.org>
In reply to#29938
On Tue, Sep 25, 2012 at 12:17 PM, Oscar Benjamin
<oscar.j.benjamin@gmail.com> wrote:
> Also I think lambda functions might be able to keep the frame alive. Are
> they by any chance being created in a function that is called in a loop?

I'm pretty sure they don't.  Closures don't keep a reference to the
calling frame, only to the appropriate cellvars.

Also note that whether a function is a closure has nothing to do with
whether it was defined by a lambda or a def statement.  In fact,
there's no difference between functions created by one vs. the other,
except that one has an interesting __name__ and the other does not.
:-)

[toc] | [prev] | [next] | [standalone]


#30135

FromTim Chase <python.list@tim.thechases.com>
Date2012-09-25 18:35 -0500
Message-ID<mailman.1386.1348616092.27098.python-list@python.org>
In reply to#29938
On 09/25/12 17:55, Oscar Benjamin wrote:
> On 25 September 2012 23:10, Tim Chase <python.list@tim.thechases.com> wrote:
>> If tuples provide a savings but you find them opaque, you might also
>> consider named-tuples for clarity.
> 
> Do they have the same memory usage?
> 
> Since tuples don't have a per-instance __dict__, I'd expect them to be a
> lot lighter. I'm not sure if I'm interpreting the results below properly
> but they seem to suggest that a namedtuple can have a memory consumption
> several times larger than an ordinary tuple.

I think the "how much memory is $METHOD using" topic of the thread
is the root of the problem.  From my testing of your question:

>>> import collections, sys
>>> A = collections.namedtuple('A', ['x', 'y'])
>>> nt = A(1,3)
>>> t = (1,3)
>>> sys.getsizeof(nt)
72
>>> sys.getsizeof(t)
72
>>> nt_s = set(dir(nt))
>>> t_s = set(dir(t))
>>> t_s ^ nt_s
set(['__module__', '_make', '_asdict', '_replace', '_fields',
'__slots__', 'y', 'x'])
>>> t_s - nt_s
set([])

So a named-tuple has 6+n (where "n" is the number of fields) extra
attributes, but it seems that namedtuples & tuples seem to occupy
the same amount of space (72).

Additionally, pulling up a second console and issuing

  ps v | grep [p]ython

shows the memory usage of the process as I perform these, and after
them, and they both show the same usage (actual test was

1) pull up a fresh python
2) import sys, collections; A = collections.namedtuple('A',['x','y'])
3) check memory usage in other window
4a) x = (1,2)
4b) x = A(1,2)
5) check memory usage again in other window
6) quit python

performing 4a on one run, and 4b on the second run.

Both showed identical memory usage as well (Debian Linux (Stable),
stock Python 2.6.6) at the system level.

I don't know if that little testing is actually worth anything, but
at least it's another data-point as we muddle towards helping
MrsEntity/junkshops.

-tkc


[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web