[Python-checkins] python/dist/src/Include ceval.h,2.46,2.47 compile.h,2.39,2.40

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Wed, 05 Feb 2003 15:13:29 -0800


Update of /cvsroot/python/python/dist/src/Include
In directory sc8-pr-cvs1:/tmp/cvs-serv3401/Include

Modified Files:
	ceval.h compile.h 
Log Message:
Small function call optimization and special build option for call stats.

-DCALL_PROFILE: Count the number of function calls executed.

When this symbol is defined, the ceval mainloop and helper functions
count the number of function calls made.  It keeps detailed statistics
about what kind of object was called and whether the call hit any of
the special fast paths in the code.

Optimization:

When we take the fast_function() path, which seems to be taken for
most function calls, and there is minimal frame setup to do, avoid
call PyEval_EvalCodeEx().  The eval code ex function does a lot of
work to handle keywords args and star args, free variables,
generators, etc.  The inlined version simply allocates the frame and
copies the arguments values into the frame.

The optimization gets a little help from compile.c which adds a
CO_NOFREE flag to code objects that don't have free variables or cell
variables.  This change allows fast_function() to get into the fast
path with fewer tests.

I measure a couple of percent speedup in pystone with this change, but
there's surely more that can be done.


Index: ceval.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/ceval.h,v
retrieving revision 2.46
retrieving revision 2.47
diff -C2 -d -r2.46 -r2.47
*** ceval.h	3 Sep 2002 20:10:44 -0000	2.46
--- ceval.h	5 Feb 2003 23:12:56 -0000	2.47
***************
*** 49,52 ****
--- 49,54 ----
  PyAPI_FUNC(char *) PyEval_GetFuncDesc(PyObject *);
  
+ PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *);
+ 
  /* this used to be handled on a per-thread basis - now just two globals */
  PyAPI_DATA(volatile int) _Py_Ticker;

Index: compile.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/compile.h,v
retrieving revision 2.39
retrieving revision 2.40
diff -C2 -d -r2.39 -r2.40
*** compile.h	11 Dec 2002 14:04:57 -0000	2.39
--- compile.h	5 Feb 2003 23:12:56 -0000	2.40
***************
*** 35,38 ****
--- 35,44 ----
  #define CO_NESTED       0x0010
  #define CO_GENERATOR    0x0020
+ /* The CO_NOFREE flag is set if there are no free or cell variables.
+    This information is redundant, but it allows a single flag test
+    to determine whether there is any extra work to be done when the
+    call frame it setup.
+ */
+ #define CO_NOFREE       0x0040
  /* XXX Temporary hack.  Until generators are a permanent part of the
     language, we need a way for a code object to record that generators