-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-44590: Lazily allocate frame objects #27077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
79aeaf6
Turn specials array into struct and add 'lasti' to it.
markshannon 3b6a4e8
Move stack-depth from frame object to specials struct.
markshannon 6f0ba40
Rename 'specials' to 'frame' as it now includes most of the data for …
markshannon 8543c27
Refactor, pushing PyFrame upward toward _PyEval_Vector.
markshannon 423d403
Add pointer from stack frame to frame object and rename tstate.frame …
markshannon 7bf6c30
More refactoring. Add tstate.frame for the top stack frame.
markshannon 861a8d9
Convert use of PyFrameObject to _PyFrame.
markshannon 35e793c
Replace most remaining uses frame object in the interpreter with stac…
markshannon 192094e
Convert more uses of frameobject to frame.
markshannon 3f601a7
Move f_state from frame object to frame.
markshannon bd95c32
Compute f_back when on thread stack, only filling in value when frame…
markshannon 9961abc
Add NULL check
markshannon 32af707
Get lazy f_back working (it still leaks).
markshannon ac7dbe8
Use frames not frameobjects in sys._getframe()
markshannon f33d291
NULL out frame->previous when leaving frame.
markshannon 5c23a36
Frames now include nlocalspuls, so they have valid layout after code …
markshannon 910e991
Move ownership of frame in generator from frame object ot generator o…
markshannon 22e1c9b
Remove localsptr field from frame object.
markshannon f84a3f0
Add new _PyEval_EvalNoFrame function for evaluating frames directly.
markshannon 1180a44
Allow for lazily created frames.
markshannon c76de89
Do not create frame objects for Python calls.
markshannon 15aeef1
Don't create frame objects for generators.
markshannon 1d2e1ce
Fix memory leak
markshannon 1b19f8b
Merge branch 'main' into lazy-frame-updated
markshannon d619bae
Restore support for PEP 523.
markshannon d147d03
Streamline pushing and popping stack frames a bit.
markshannon 25c6a71
Merge branch 'main' into lazy-frame
markshannon 618b094
Add f_ prefix back to several frame fields to ease porting C code tha…
markshannon e5da338
Add NEWS
markshannon dda0b0c
Remove debugging artifact.
markshannon 5ecc067
Make symbol private
markshannon 3b65a0f
Fix use-after-free error.
markshannon 596213d
Add some explanatory comments.
markshannon 386275e
Remove debugging artifact.
markshannon 596c041
Merge branch 'main' into lazy-frame
markshannon 039bca7
Rename _PyFrame to InterpreterFrame.
markshannon 2cad33b
Remove use-after-free in assert.
markshannon 77cf187
Merge branch 'main' into lazy-frame
markshannon decf209
Make name of frame argument consistent across _PyEval_Vector, _PyEval…
markshannon 666b618
Allow for old gdbs still using Python 2.
markshannon 90ed5b6
Various small clarifications as suggested by Pablo.
markshannon 593a348
Refactor interpreter frame code into its own file. Improve a few names.
markshannon b775f13
Tidy up assert.
markshannon e8476b2
Fix warning on Windows.
markshannon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Misc/NEWS.d/next/Core and Builtins/2021-07-09-12-08-17.bpo-44590.a2ntVX.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
All necessary data for executing a Python function (local variables, stack, | ||
etc) is now kept in a per-thread stack. Frame objects are lazily allocated | ||
on demand. This increases performance by about 7% on the standard benchmark | ||
suite. Introspection and debugging are unaffected as frame objects are | ||
always available when needed. Patch by Mark Shannon. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
#include "pycore_pymem.h" // _Py_tracemalloc_config | ||
#include "pycore_traceback.h" | ||
#include "pycore_hashtable.h" | ||
#include "frameobject.h" // PyFrame_GetBack() | ||
#include <pycore_frame.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m curious why this one is included with |
||
|
||
#include "clinic/_tracemalloc.c.h" | ||
/*[clinic input] | ||
|
@@ -299,18 +299,16 @@ hashtable_compare_traceback(const void *key1, const void *key2) | |
|
||
|
||
static void | ||
tracemalloc_get_frame(PyFrameObject *pyframe, frame_t *frame) | ||
tracemalloc_get_frame(InterpreterFrame *pyframe, frame_t *frame) | ||
{ | ||
frame->filename = unknown_filename; | ||
int lineno = PyFrame_GetLineNumber(pyframe); | ||
int lineno = PyCode_Addr2Line(pyframe->f_code, pyframe->f_lasti*2); | ||
if (lineno < 0) { | ||
lineno = 0; | ||
} | ||
frame->lineno = (unsigned int)lineno; | ||
|
||
PyCodeObject *code = PyFrame_GetCode(pyframe); | ||
PyObject *filename = code->co_filename; | ||
Py_DECREF(code); | ||
PyObject *filename = pyframe->f_code->co_filename; | ||
|
||
if (filename == NULL) { | ||
#ifdef TRACE_DEBUG | ||
|
@@ -395,7 +393,7 @@ traceback_get_frames(traceback_t *traceback) | |
return; | ||
} | ||
|
||
PyFrameObject *pyframe = PyThreadState_GetFrame(tstate); | ||
InterpreterFrame *pyframe = tstate->frame; | ||
for (; pyframe != NULL;) { | ||
if (traceback->nframe < _Py_tracemalloc_config.max_nframe) { | ||
tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]); | ||
|
@@ -406,8 +404,7 @@ traceback_get_frames(traceback_t *traceback) | |
traceback->total_nframe++; | ||
} | ||
|
||
PyFrameObject *back = PyFrame_GetBack(pyframe); | ||
Py_DECREF(pyframe); | ||
InterpreterFrame *back = pyframe->previous; | ||
pyframe = back; | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.