Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 008d8ef

Browse files
committed
Merged revisions 67494 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r67494 | jeffrey.yasskin | 2008-12-02 22:46:45 -0800 (Tue, 02 Dec 2008) | 5 lines Speed up Python (according to pybench and 2to3-on-itself) by 1-2% by caching whether any thread has tracing turned on, which saves one load instruction in the fast_next_opcode path in PyEval_EvalFrameEx(). See issue 4477. ........
1 parent fd24b32 commit 008d8ef

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Python/ceval.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,13 @@ enum why_code {
508508
static enum why_code do_raise(PyObject *, PyObject *);
509509
static int unpack_iterable(PyObject *, int, int, PyObject **);
510510

511+
/* Records whether tracing is on for any thread. Counts the number of
512+
threads for which tstate->c_tracefunc is non-NULL, so if the value
513+
is 0, we know we don't have to check this thread's c_tracefunc.
514+
This speeds up the if statement in PyEval_EvalFrameEx() after
515+
fast_next_opcode*/
516+
static int _Py_TracingPossible = 0;
517+
511518
/* for manipulating the thread switch and periodic "stuff" - used to be
512519
per thread, now just a pair o' globals */
513520
int _Py_CheckInterval = 100;
@@ -957,7 +964,8 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
957964

958965
/* line-by-line tracing support */
959966

960-
if (tstate->c_tracefunc != NULL && !tstate->tracing) {
967+
if (_Py_TracingPossible &&
968+
tstate->c_tracefunc != NULL && !tstate->tracing) {
961969
/* see maybe_call_line_trace
962970
for expository comments */
963971
f->f_stacktop = stack_pointer;
@@ -3162,6 +3170,7 @@ PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
31623170
{
31633171
PyThreadState *tstate = PyThreadState_GET();
31643172
PyObject *temp = tstate->c_traceobj;
3173+
_Py_TracingPossible += (func != NULL) - (tstate->c_tracefunc != NULL);
31653174
Py_XINCREF(arg);
31663175
tstate->c_tracefunc = NULL;
31673176
tstate->c_traceobj = NULL;

0 commit comments

Comments
 (0)