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

Created on 2021-07-09 10:53 by Mark.Shannon, last changed 2021-08-01 13:19 by ncoghlan. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27077 merged Mark.Shannon, 2021-07-09 11:29
PR 27525 open ncoghlan, 2021-08-01 08:30
Messages (3)
msg397196 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-07-09 10:53
In https://bugs.python.org/issue44032 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)
https://github.com/python/cpython/commit/ae0a2b756255629140efcbe57fc2e714f0267aa3
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.
History
Date User Action Args
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