[Python-Dev] tiny optimization in ceval mainloop

Jeremy Hylton jeremy@alum.mit.edu
Thu, 29 Aug 2002 19:28:36 -0400


I noticed that one frequently executed line in the mainloop is testing
whether either the ticker has dropped to 0 or if there are
things_to_do.  Would it be kosher to just drop the ticker to 0 whenever
things_to_do is set to true?  Then you'd only need to check the ticker
each time through.

Jeremy

Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.332
diff -c -c -r2.332 ceval.c
*** ceval.c	23 Aug 2002 14:11:35 -0000	2.332
--- ceval.c	29 Aug 2002 23:19:18 -0000
***************
*** 378,383 ****
--- 378,384 ----
  int
  Py_AddPendingCall(int (*func)(void *), void *arg)
  {
+ 	PyThreadState *tstate;
  	static int busy = 0;
  	int i, j;
  	/* XXX Begin critical section */
***************
*** 395,400 ****
--- 396,404 ----
  	pendingcalls[i].func = func;
  	pendingcalls[i].arg = arg;
  	pendinglast = j;
+ 	
+ 	tstate = PyThreadState_GET();
+ 	tstate->ticker = 0;
  	things_to_do = 1; /* Signal main loop */
  	busy = 0;
  	/* XXX End critical section */
***************
*** 669,675 ****
  		   async I/O handler); see Py_AddPendingCall() and
  		   Py_MakePendingCalls() above. */
  
! 		if (things_to_do || --tstate->ticker < 0) {
  			tstate->ticker = tstate->interp->checkinterval;
  			if (things_to_do) {
  				if (Py_MakePendingCalls() < 0) {
--- 673,679 ----
  		   async I/O handler); see Py_AddPendingCall() and
  		   Py_MakePendingCalls() above. */
  
! 		if (--tstate->ticker < 0) {
  			tstate->ticker = tstate->interp->checkinterval;
  			if (things_to_do) {
  				if (Py_MakePendingCalls() < 0) {