Skip to content

[3.12] GH-127953: Make line number lookup O(1) regardless of the size of the code object (GH-129127) #132268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 3.12
Choose a base branch
from

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Apr 8, 2025

Manual backport of #129127.

This probably isn't getting merged into 3.12 (that's up to @Yhg1s), but I wanted to make available to anyone who wants it in their 3.12

…e size of the code object (python#129127)

pythonGH-127953: Make line number lookup O(1) regardless of the size of the code object (pythonGH-128350)
@markshannon markshannon changed the title [3.12] GH-127953: Make line number lookup O(1) regardless of the size… [3.12] GH-127953: Make line number lookup O(1) regardless of the size of the code object (GH-129127) Apr 8, 2025
Copy link

@kmoffett kmoffett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there may have been a backport-merge issue in Python/ceval.c; the change to that file in GH-127953 doesn't make sense in Python 3.12 because the code doesn't exist in that revision (it was added by GH-114986 post-3.12).

Comment on lines -863 to +881
_PyFrame_SetStackPointer(frame, stack_pointer);
int original_opcode = _Py_call_instrumentation_line(
tstate, frame, here, prev);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (original_opcode < 0) {
next_instr = here+1;
goto error;
int original_opcode = 0;
if (tstate->tracing) {
PyCodeObject *code = frame->f_code;
int index = (int)(here - _PyCode_CODE(code));
original_opcode = code->_co_monitoring->lines->data[index*code->_co_monitoring->lines->bytes_per_entry];
}
next_instr = frame->prev_instr;
if (next_instr != here) {
DISPATCH();
else {
_PyFrame_SetStackPointer(frame, stack_pointer);
original_opcode = _Py_call_instrumentation_line(
tstate, frame, here, prev);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (original_opcode < 0) {
next_instr = here+1;
goto error;
}
next_instr = frame->prev_instr;
if (next_instr != here) {
DISPATCH();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong; this isn't present in the original change, but is instead a partial backport of GH-114986

PyCodeAddressRange range;
_PyCode_InitAddressRange(code, &range);
int max_line = code->co_firstlineno + 1;
_PyCode_InitAddressRange(code, &range);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line appears to be a copy-paste error; it duplicates line 1553 above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants