GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Reduce padding in `_PyCfgBasicblock` · Issue #160132 · python/cpython

Reduce padding in _PyCfgBasicblock #160132

New issue
Copy link
New issue
Copy link
Closed
#160149
Closed
Reduce padding in _PyCfgBasicblock#160132
#160149
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Description

@ashm-dev
ashm-dev
opened on Oct 21, 2026
Issue body actions

Feature or enhancement

On my x86-64 build, _PyCfgBasicblock in Python/flowgraph.c occupies 72 bytes. The layout reported by pahole contains:

  • A 4-byte alignment gap immediately after b_label, at offsets 12–15.
  • Five one-bit flags starting at offset 64.
  • Trailing padding bringing the total size to 72 bytes.

Moving the five bit-fields immediately after b_label should fill the existing gap and reduce the structure to 64 bytes on this platform, without changing the offsets of the remaining fields.

This would save 8 bytes per CFG block before allocator rounding. With the standard 64-bit pymalloc size classes, the allocation would also move from the 80-byte class to the 64-byte class.

The proposed change is limited to the layout of this internal structure. No compiler behavior or public API changes are intended. Compilation performance has not been benchmarked.

❯ pahole -C _PyCfgBasicblock Python/flowgraph.o
struct _PyCfgBasicblock {
	struct _PyCfgBasicblock *  b_list;               /*     0     8 */
	_PyJumpTargetLabel         b_label;              /*     8     4 */

	/* XXX 4 bytes hole, try to pack */

	struct _PyCfgExceptStack * b_exceptstack;        /*    16     8 */
	cfg_instr *                b_instr;              /*    24     8 */
	struct _PyCfgBasicblock *  b_next;               /*    32     8 */
	int                        b_iused;              /*    40     4 */
	int                        b_ialloc;             /*    44     4 */
	uint64_t                   b_unsafe_locals_mask; /*    48     8 */
	int                        b_predecessors;       /*    56     4 */
	int                        b_startdepth;         /*    60     4 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	unsigned int               b_preserve_lasti:1;   /*    64: 0  4 */
	unsigned int               b_visited:1;          /*    64: 1  4 */
	unsigned int               b_except_handler:1;   /*    64: 2  4 */
	unsigned int               b_cold:1;             /*    64: 3  4 */
	unsigned int               b_warm:1;             /*    64: 4  4 */

	/* size: 72, cachelines: 2, members: 15 */
	/* sum members: 60, holes: 1, sum holes: 4 */
	/* sum bitfield members: 5 bits (0 bytes) */
	/* padding: 4 */
	/* bit_padding: 27 bits */
	/* last cacheline: 8 bytes */
};

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-160132: Reduce padding in _PyCfgBasicblock #160149

Activity

  1. ashm-dev
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Oct 21, 2026
  2. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Oct 21, 2026
  3. iritkatriel
    added a commit that references this issue on Oct 22, 2026

    Merge branch 'main' into pythongh-160132

    d7f0aa3
  4. ashm-dev
    added a commit that references this issue on Oct 27, 2026

    Merge branch 'main' into pythongh-160132

    24cb647
  5. iritkatriel
    added a commit that references this issue on Oct 28, 2026

    gh-160132: Reduce padding in _PyCfgBasicblock (#160149)

    e354246
  6. iritkatriel
    closed this as completedin #160149on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.