Monday, June 18, 2007

Python 2.5 consumes more memory than 2.4.4

Since python 2.5 contains a new object allocator that is able to return memory to the operating system, I was surprised to find that python 2.5.1 consumes more memory at start-up than 2.4.4 does (at least on Windows). I have been assuming that 2.5.1 could only use the same or less memory than python 2.4.4. However, simply starting each interactive interpreter on my Windows XP machine, the Task Manager reports:
Version "Mem Usage" "VM Size"
Python 2.4.4 3440k 1788k
Python 2.5.1 5828k 3868k

The specific builds tested where:
  • Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
  • Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
Which were installed using the Windows Installers on the python.org web site as of today.

Of course, depending on your application, I would expect python 2.5.1 to still use less memory overall. But what surprised me was how much of a handicap python 2.5.1 has after just loading the interpreter: it starts out consuming over 2 megabytes more memory.

3 comments:

David Niergarth said...

That's a big difference! Maybe you should ask on c.l.p.

FWIW, I don't see a big difference under Linux (Ubuntu).

% top -p 30660,30661

PID VIRT RES SHR COMMAND
30660 4564 2740 1640 python2.4
30661 4708 2872 1708 python2.5

(I'm using 2.4.4 and 2.5.1.)

The fact that Python now releases memory back to the OS is huge for long-running processes.

Kelly Yancey said...

Thanks for the info! I was really surprised by the difference on Windows also. It is good to see there isn't much difference on Linux. When I get some more time, I'm planning on trying to track down why such a large increase in VM size on Windows because it will affect whether we port an application at work to 2.5. I'll be sure to post the results here too.

bear said...

I am very interested in the result of why such a large increase in VM size on Windows. Do you find the reason?

Thanks.