summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-06-20 12:00:42 (GMT)
committerGitHub <noreply@github.com>2022-06-20 12:00:42 (GMT)
commitab0e60101637b7cf47f3cc95813996791e7118c4 (patch)
treec0590854ab9e9137c872f0789763d7bb07151fb0 /Python
parent45e62a2bc1c0000e2e9b613fff6bebf2c26fcb93 (diff)
downloadcpython-ab0e60101637b7cf47f3cc95813996791e7118c4.zip
cpython-ab0e60101637b7cf47f3cc95813996791e7118c4.tar.gz
cpython-ab0e60101637b7cf47f3cc95813996791e7118c4.tar.bz2
GH-93516: Speedup line number checks when tracing. (GH-93763)
* Use a lookup table to reduce overhead of getting line numbers during tracing.
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 19b2bb4..a23ed58 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -6799,9 +6799,10 @@ call_trace(Py_tracefunc func, PyObject *obj,
tstate->tracing_what = what;
PyThreadState_EnterTracing(tstate);
assert(_PyInterpreterFrame_LASTI(frame) >= 0);
- initialize_trace_info(&tstate->trace_info, frame);
- int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT);
- f->f_lineno = _PyCode_CheckLineNumber(addr, &tstate->trace_info.bounds);
+ if (_PyCode_InitLineArray(frame->f_code)) {
+ return -1;
+ }
+ f->f_lineno = _PyCode_LineNumberFromArray(frame->f_code, _PyInterpreterFrame_LASTI(frame));
result = func(obj, f, what, arg);
f->f_lineno = 0;
PyThreadState_LeaveTracing(tstate);
@@ -6838,16 +6839,17 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
represents a jump backwards, update the frame's line number and
then call the trace function if we're tracing source lines.
*/
- initialize_trace_info(&tstate->trace_info, frame);
+ if (_PyCode_InitLineArray(frame->f_code)) {
+ return -1;
+ }
int lastline;
if (instr_prev <= frame->f_code->_co_firsttraceable) {
lastline = -1;
}
else {
- lastline = _PyCode_CheckLineNumber(instr_prev*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds);
+ lastline = _PyCode_LineNumberFromArray(frame->f_code, instr_prev);
}
- int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT);
- int line = _PyCode_CheckLineNumber(addr, &tstate->trace_info.bounds);
+ int line = _PyCode_LineNumberFromArray(frame->f_code, _PyInterpreterFrame_LASTI(frame));
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
if (f == NULL) {
return -1;