[Python-Dev] Reduce memory footprint of Python

R. David Murray rdmurray at bitdance.com
Tue Oct 8 17:33:53 CEST 2013


On Sun, 06 Oct 2013 22:27:52 +0200, martin at v.loewis.de wrote:
> 
> Quoting Benjamin Peterson <benjamin at python.org>:
> 
> >> If you know that your application uses a lot of memory, it is
> >> interesting to sometimes (when the application is idle) try to release
> >> some bytes to not use all the system memory. On embedded devices,
> >> memory is expensive and very limited. Each byte is important :-)
> >
> > How many embedded systems are running Python?
> 
> And of those, how many use the linecache module?

I can give you one data point: a mobile platform that (currently) uses
Python3, and does not use linecache because of how much memory it
consumes.

As far as the other caches go, every MB counts if you don't have swap,
even if you have 2GB of RAM.  And especially if you don't :)

Like Victor, I spent quite a bit of time helping to trim a MB here and a
MB there.  I would have loved to have had his tools for doing that work!
Trimming linecache was one of the early big wins, even though it made
some aspects of development harder.  We also cleared most of the other
caches after startup (of a long running process).

--David

PS: I have always thought it sad that the ready availability of memory,
CPU speed, and disk space tends to result in lazy programs.  I understand
there is an effort/value tradeoff, and I make those tradeoffs myself
all the time...but it still makes me sad.  Then, again, in my early
programming days I spent a fair amount of time writing and using Forth,
and that probably colors my worldview. :)


More information about the Python-Dev mailing list