[pypy-dev] Questions for Armin

Edward K. Ream edream at tds.net
Sun Jan 19 13:47:05 CET 2003

> >Yes.  I have been focusing on an "accounting" question: how often does
> >compiler run?  If the compiler starts from scratch every time a program
> >run, then I gather from your example that the compiler will be called
> >for every type of very argument for every executed function _every time
> >program runs_.  Perhaps you are assuming that the gains from compiling
> >be so large that it doesn't matter how often the compiler runs.

> Well, if most everything is written in python, with all  the
> libraries etc., I  think there still  is some accounting  to
> do. I.e.,  library modules  won't change  much after  having
> been exercised a bit. Will this keep updating cached info in
> pyc (or maybe  new .pyp)  files?

Good question.  Here is something I sent privately to Christian:

To run a program: [using .pyp files]

1. Load the byte code, performing any queued requests for optimizations
using stored data.  In general, there will be no such requests after the
first few runs.  Obviously, changing the Python source code throws out some
or all of this intermediate data.

2. Run the code, doing some optimizations immediately, possibly requesting
other optimizations to be done later, and storing any useful data in the
"extended byte code".  At first the code will be intepreted/git'ed.  After a
few runs there will be nothing left but globally optimized machine code.  It
doesn't get any better than this.

In short, the code gets faster the more it is executed.  This approach
should make bootstrapping easy.  You could even start with an interp that
just queues up optimization requests for the next load time!

So I am thinking that the only time this machine code in the byte code (.pyp
file) changes is if the jit/interpreter/psyco/whatever-you-call-it sees an
object with a type that it has never seen before.  After a very few runs (of
any particular .pyp file) the cached data becomes nothing but machine code
(with branches to uncommon_case that never get taken). I see the situation
as being similar to a peephole optimizer:  it takes only 2 or 3 iterations
to perform all possible optimizations.  Since the Python code of libraries
and other "system" code never changes (or hardly ever changes), we should be

Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html

More information about the Pypy-dev mailing list