[issue47177] Frames should store next_instr instead of lasti

Brandt Bucher report at bugs.python.org
Wed Mar 30 21:12:26 EDT 2022


New submission from Brandt Bucher <brandtbucher at gmail.com>:

Rather than maintaining the offset of the "last instruction" (`f_lasti`), interpreter frames should instead just maintain a pointer to the true next instruction. This has several benefits, most notably reducing the register pressure associated with loading first_instr on every instruction and call in the main interpreter loop:

When entering a frame:

- Before: `next_instr = first_instr + frame->f_lasti + 1;`
- After:  `next_instr = frame->next_instr;`

When starting a new instruction:

- Before: `frame->next_instr = next_instr++ - first_instr;`
- After:  `frame->next_instr = ++next_instr;`

Benchmarks suggest that this overhead is surprisingly significant (something like 2%).

----------
assignee: brandtbucher
components: Interpreter Core
messages: 416409
nosy: Mark.Shannon, brandtbucher
priority: normal
severity: normal
stage: patch review
status: open
title: Frames should store next_instr instead of lasti
type: performance
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47177>
_______________________________________


More information about the Python-bugs-list mailing list