mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
Unblocked and merged revisions 67494 via svnmerge from
svn+ssh://pythondev@svn.python.org/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. ........
This commit is contained in:
parent
696d6ba6b9
commit
d0a70d4bab
1 changed files with 10 additions and 1 deletions
|
@ -504,6 +504,13 @@ enum why_code {
|
||||||
static enum why_code do_raise(PyObject *, PyObject *, PyObject *);
|
static enum why_code do_raise(PyObject *, PyObject *, PyObject *);
|
||||||
static int unpack_iterable(PyObject *, int, PyObject **);
|
static int unpack_iterable(PyObject *, int, PyObject **);
|
||||||
|
|
||||||
|
/* Records whether tracing is on for any thread. Counts the number of
|
||||||
|
threads for which tstate->c_tracefunc is non-NULL, so if the value
|
||||||
|
is 0, we know we don't have to check this thread's c_tracefunc.
|
||||||
|
This speeds up the if statement in PyEval_EvalFrameEx() after
|
||||||
|
fast_next_opcode*/
|
||||||
|
static int _Py_TracingPossible = 0;
|
||||||
|
|
||||||
/* for manipulating the thread switch and periodic "stuff" - used to be
|
/* for manipulating the thread switch and periodic "stuff" - used to be
|
||||||
per thread, now just a pair o' globals */
|
per thread, now just a pair o' globals */
|
||||||
int _Py_CheckInterval = 100;
|
int _Py_CheckInterval = 100;
|
||||||
|
@ -886,7 +893,8 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
||||||
|
|
||||||
/* line-by-line tracing support */
|
/* line-by-line tracing support */
|
||||||
|
|
||||||
if (tstate->c_tracefunc != NULL && !tstate->tracing) {
|
if (_Py_TracingPossible &&
|
||||||
|
tstate->c_tracefunc != NULL && !tstate->tracing) {
|
||||||
/* see maybe_call_line_trace
|
/* see maybe_call_line_trace
|
||||||
for expository comments */
|
for expository comments */
|
||||||
f->f_stacktop = stack_pointer;
|
f->f_stacktop = stack_pointer;
|
||||||
|
@ -3432,6 +3440,7 @@ PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = PyThreadState_GET();
|
PyThreadState *tstate = PyThreadState_GET();
|
||||||
PyObject *temp = tstate->c_traceobj;
|
PyObject *temp = tstate->c_traceobj;
|
||||||
|
_Py_TracingPossible += (func != NULL) - (tstate->c_tracefunc != NULL);
|
||||||
Py_XINCREF(arg);
|
Py_XINCREF(arg);
|
||||||
tstate->c_tracefunc = NULL;
|
tstate->c_tracefunc = NULL;
|
||||||
tstate->c_traceobj = NULL;
|
tstate->c_traceobj = NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue