This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Frames should store next_instr instead of lasti
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brandtbucher Nosy List: Mark.Shannon, brandtbucher
Priority: normal Keywords: patch

Created on 2022-03-31 01:12 by brandtbucher, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 32208 merged brandtbucher, 2022-03-31 01:16
Messages (2)
msg416409 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-03-31 01:12
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%).
msg416938 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-04-07 19:31
New changeset ef6a482b0285870c45f39c9b17ed827362b334ae by Brandt Bucher in branch 'main':
bpo-47177: Replace `f_lasti` with `prev_instr` (GH-32208)
https://github.com/python/cpython/commit/ef6a482b0285870c45f39c9b17ed827362b334ae
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91333
2022-04-07 19:32:09brandtbuchersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-04-07 19:31:05brandtbuchersetmessages: + msg416938
2022-03-31 01:16:18brandtbuchersetkeywords: + patch
pull_requests: + pull_request30283
2022-03-31 01:12:26brandtbuchercreate