From bbe6b3d5d5ce3766c8e3d239c2fdb3b42462e915 Mon Sep 17 00:00:00 2001 From: Mikhail Efimov Date: Fri, 21 Nov 2025 11:51:40 +0300 Subject: [PATCH 1/2] Remove mention of _PyThreadState_BumpFramePointer --- InternalDocs/interpreter.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/InternalDocs/interpreter.md b/InternalDocs/interpreter.md index 38e9f6fced6088..e1b17b91ab320d 100644 --- a/InternalDocs/interpreter.md +++ b/InternalDocs/interpreter.md @@ -226,10 +226,11 @@ Up through 3.10, the call stack was implemented as a singly-linked list of heap allocation for the stack frame. Since 3.11, frames are no longer fully-fledged objects. Instead, a leaner internal -`_PyInterpreterFrame` structure is used, which is allocated using a custom allocator -function (`_PyThreadState_BumpFramePointer()`), which allocates and initializes a -frame structure. Usually a frame allocation is just a pointer bump, which improves -memory locality. +`_PyInterpreterFrame` structure is used. Most frames are allocated contiguously in a +per-thread stack (see `_PyThreadState_PushFrame` in [Python/pystate.c](../Python/pystate.c)), +which improves memory locality and reduces overhead. +If current `datastack_chunk` has enough space (`_PyThreadState_HasStackSpace`) +then lightweight `_PyFrame_PushUnchecked` can be used. Sometimes an actual `PyFrameObject` is needed, such as when Python code calls `sys._getframe()` or an extension module calls From 7c78bb15c4d01da126bc3884b88d648a8dbdfff3 Mon Sep 17 00:00:00 2001 From: Mikhail Efimov Date: Fri, 21 Nov 2025 13:39:38 +0300 Subject: [PATCH 2/2] Update InternalDocs/interpreter.md Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- InternalDocs/interpreter.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/InternalDocs/interpreter.md b/InternalDocs/interpreter.md index e1b17b91ab320d..75acdf596a7f30 100644 --- a/InternalDocs/interpreter.md +++ b/InternalDocs/interpreter.md @@ -229,8 +229,8 @@ Since 3.11, frames are no longer fully-fledged objects. Instead, a leaner intern `_PyInterpreterFrame` structure is used. Most frames are allocated contiguously in a per-thread stack (see `_PyThreadState_PushFrame` in [Python/pystate.c](../Python/pystate.c)), which improves memory locality and reduces overhead. -If current `datastack_chunk` has enough space (`_PyThreadState_HasStackSpace`) -then lightweight `_PyFrame_PushUnchecked` can be used. +If the current `datastack_chunk` has enough space (`_PyThreadState_HasStackSpace`) +then the lightweight `_PyFrame_PushUnchecked` can be used instead of `_PyThreadState_PushFrame`. Sometimes an actual `PyFrameObject` is needed, such as when Python code calls `sys._getframe()` or an extension module calls