From a1e3f749e63bed3b8f3818fc24a039b608dd08bb Mon Sep 17 00:00:00 2001 From: Shamil Abdulaev Date: Thu, 22 Oct 2026 02:26:51 +0300 Subject: [PATCH] perf(compiler): reduce padding in _PyCfgBasicblock --- ...-10-21-23-18-38.gh-issue-160132.Nj4rQa.rst | 3 +++ Python/flowgraph.c | 20 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-10-21-23-18-38.gh-issue-160132.Nj4rQa.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-21-23-18-38.gh-issue-160132.Nj4rQa.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-21-23-18-38.gh-issue-160132.Nj4rQa.rst new file mode 100644 index 000000000000000..156f387f7a69983 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-21-23-18-38.gh-issue-160132.Nj4rQa.rst @@ -0,0 +1,3 @@ +Reduce memory usage during compilation by reordering the fields of the +internal basic block structure to reduce padding. +Patch by Shamil Abdulaev. diff --git a/Python/flowgraph.c b/Python/flowgraph.c index 17489ae5bfb5252..9248138ba20ac93 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -47,6 +47,16 @@ typedef struct _PyCfgBasicblock { struct _PyCfgBasicblock *b_list; /* The label of this block if it is a jump target, -1 otherwise */ _PyJumpTargetLabel b_label; + /* Basic block is an exception handler that preserves lasti */ + unsigned b_preserve_lasti : 1; + /* Used by compiler passes to mark whether they have visited a basic block. */ + unsigned b_visited : 1; + /* b_except_handler is used by the cold-detection algorithm to mark exception targets */ + unsigned b_except_handler : 1; + /* b_cold is true if this block is not perf critical (like an exception handler) */ + unsigned b_cold : 1; + /* b_warm is used by the cold-detection algorithm to mark blocks which are definitely not cold */ + unsigned b_warm : 1; /* Exception stack at start of block, used by assembler to create the exception handling table */ struct _PyCfgExceptStack *b_exceptstack; /* pointer to an array of instructions, initially NULL */ @@ -64,16 +74,6 @@ typedef struct _PyCfgBasicblock { int b_predecessors; /* depth of stack upon entry of block, computed by stackdepth() */ int b_startdepth; - /* Basic block is an exception handler that preserves lasti */ - unsigned b_preserve_lasti : 1; - /* Used by compiler passes to mark whether they have visited a basic block. */ - unsigned b_visited : 1; - /* b_except_handler is used by the cold-detection algorithm to mark exception targets */ - unsigned b_except_handler : 1; - /* b_cold is true if this block is not perf critical (like an exception handler) */ - unsigned b_cold : 1; - /* b_warm is used by the cold-detection algorithm to mark blocks which are definitely not cold */ - unsigned b_warm : 1; } basicblock;