◐ Shell
reader mode source ↗
Skip to content

bpo-44590: Lazily allocate frame objects#27077

Merged
markshannon merged 44 commits into
python:mainfrom
faster-cpython:lazy-frame
Jul 26, 2021
Merged

bpo-44590: Lazily allocate frame objects#27077
markshannon merged 44 commits into
python:mainfrom
faster-cpython:lazy-frame

Conversation

@markshannon

@markshannon markshannon commented Jul 9, 2021

Copy link
Copy Markdown
Member

This PR:

  1. Moves all essential frame data to the (per-thread) stack
  2. Lazily allocates heap frame objects only when needed.

For most calls to Python functions, we can get the necessary memory for a stack frame by just bumping a pointer.
When we do need a frame object, for tracebacks and the like, it is lazily allocated.

According to my benchmarking run this PR produces a maximum speedup of 31% with a mean of 7%!

The performance numbers are suspiciously good.
If someone could run the comparison on their machine that would be much appreciated.

https://bugs.python.org/issue44590

…to tstate.pyframe as preparation for lazily created frames.
93 hidden items Load more…
@markshannon markshannon requested a review from a team as a code owner July 21, 2021 12:26

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

LGTM Great job!

Let's run the buildbots and land!

@markshannon markshannon added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 26, 2021
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @markshannon for commit e8476b2 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 26, 2021
@markshannon

Copy link
Copy Markdown
Member Author

The failures on buildbot/AMD64 Windows10 PR look like something is wrong with that machine.

@markshannon markshannon merged commit ae0a2b7 into python:main Jul 26, 2021
@ncoghlan

ncoghlan commented Aug 1, 2021

Copy link
Copy Markdown
Contributor

One consequence of this change is that the code is now quite confusing, since the term "frame" is used ambiguously to refer to both frame objects and interpreter frames (specifically, the f_frame field on frame objects is now an interpreter frame reference, while tb_frame on tracebacks is still a full frame object).

@ncoghlan

ncoghlan commented Aug 1, 2021

Copy link
Copy Markdown
Contributor

The generator code uses gi_xframe rather than gi_frame to make the distinction a bit clearer, and I think doing that systematically (so there is consistent code level distinction between execution frames and introspection frames) would make the new code much easier to follow.

@ncoghlan

ncoghlan commented Aug 1, 2021

Copy link
Copy Markdown
Contributor

I've posted a proposed internal API refactoring design here: https://bugs.python.org/issue44800

@ncoghlan

ncoghlan commented Aug 1, 2021

Copy link
Copy Markdown
Contributor

And the PR implementing that proposed refactoring is up at #27525

@markshannon markshannon deleted the lazy-frame branch September 15, 2021 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants