views:

458

answers:

4

Psyco is a specialising compiler for Python. The documentation states

Psyco can and will use large amounts of memory.

What are the main reasons for this memory usage? Is substantial memory overhead a feature of JIT compilers in general?

Edit: Thanks for the answers so far. There are three likely contenders.

  • Writing multiple specialised blocks, each of which require memory
  • Overhead due to compiling source on the fly
  • Overhead due to capturing enough data to do dynamic profiling

The question is, which one is the dominant factor in memory usage? I have my own opinion. But I'm adding a bounty, because I'd like to accept the answer that's actually correct! If anyone can demonstrate or prove where the majority of the memory is used, I'll accept it. Otherwise whoever the community votes for will be auto-accepted at the end of the bounty.

+1  A: 

The memory overhead of Psyco is currently large. I has been reduced a bit over time, but it is still an overhead. This overhead is proportional to the amount of Python code that Psyco rewrites; thus if your application has a few algorithmic "core" functions, these are the ones you will want Psyco to accelerate --- not the whole program.

So I would think the large memory requirements are due to the fact that it's loading source into memory and then compiling it as it goes. The more source you try and compile the more it's going to need. I'd guess that if it's trying to optomise it on top of that, it'll look at multiple possible solutions to try and identify the best case.

Jon Cage
+8  A: 

From psyco website "The difference with the traditional approach to JIT compilers is that Psyco writes several version of the same blocks (a block is a bit of a function), which are optimized by being specialized to some kinds of variables (a "kind" can mean a type, but it is more general)"

+4  A: 
Pete Kirkham
unwind
You can definitely add members and functions to an instantiation of a class on the fly. You could unload, modify then reload a module containing a class and start usnig the new one too.
Jon Cage
Does that change existing objects with that class, or only new ones created after the reload?
Pete Kirkham
If you change the class, created objects remain existing with the original class. You can modify directly an object to make it different to the original class too.
voyager
+1  A: 

Definitely psyco memory usage comes from compiled assembler blocks. Psyco suffers sometimes from overspecialization of functions, which means there are multiple versions of assembler blocks. Also, which is also very important, psyco never frees once allocated assembler blocks even if the code assosciated with it is dead.

If you run your program under linux you can look at /proc/xxx/smaps to see a growing block of anonymous memory, which is in different region than heap. That's anonymously mmap'ed part for writing down assembler, which of course disappears when running without psyco.

fijal