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.

Title: Create frame objects lazily when needed
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.11
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Mark.Shannon Nosy List: Mark.Shannon, gvanrossum, ncoghlan, pablogsal, vstinner
Priority: normal Keywords: patch

Created on 2021-07-09 10:53 by Mark.Shannon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27077 merged Mark.Shannon, 2021-07-09 11:29
PR 27525 closed ncoghlan, 2021-08-01 08:30
Messages (4)
msg397196 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-07-09 10:53
In we moved most of the data in the frame stack, that is the locals, stack, and "specials" (globals, builtins, code etc), from the heap allocated stack to a (mostly) contiguous array in memory.
That offered some speed up due to better cache locality, and faster allocation of frame objects (they are now fixed size so can use a simple freelist).

However, data is still split between the stack allocated frame and the heap allocated frame.

We should move the remaining data to the stack and only allocate heap objects lazily when needed for tracebacks and the like. This should improve performance further by removing the vast majority of heap frame allocations and further improving locality of reference.

Not only does this have immediate performance benefits, it also paves the way for even better Python-to-Python calls by allowing stack frames to overlap and pass arguments with the minimal amount of copying and INCREF/DECREF pairs.
msg398220 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-07-26 10:22
New changeset ae0a2b756255629140efcbe57fc2e714f0267aa3 by Mark Shannon in branch 'main':
bpo-44590: Lazily allocate frame objects (GH-27077)
msg398696 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2021-08-01 13:19
The newly linked pull request isn't actually for this ticket, it's for bpo-44800, a follow-up refactoring proposal related to the variable, struct field, and API naming schemes used for the new lighter weight execution frames.

However, the commit message and PR description refer back to this ticket as well, so the RoundUp automation picked it up.
msg413798 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-23 15:14
I created bpo-46836: "[C API] Move PyFrameObject to the internal C API".
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88756
2022-02-23 15:14:23vstinnersetnosy: + vstinner
messages: + msg413798
2021-08-01 13:19:21ncoghlansetmessages: + msg398696
2021-08-01 08:30:36ncoghlansetnosy: + ncoghlan

pull_requests: + pull_request26041
2021-08-01 01:48:47ncoghlanlinkissue44800 dependencies
2021-07-29 10:31:08Mark.Shannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-07-26 10:22:28Mark.Shannonsetmessages: + msg398220
2021-07-09 11:29:13Mark.Shannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request25626
2021-07-09 10:53:40Mark.Shannoncreate