Skip to content

gh-148675: Optimize arraydescr structure: use char[3] - #149455

Merged
encukou merged 1 commit into
python:mainfrom
vstinner:array_typecode
May 6, 2026
Merged

gh-148675: Optimize arraydescr structure: use char[3]#149455
encukou merged 1 commit into
python:mainfrom
vstinner:array_typecode

Conversation

@vstinner

@vstinnervstinner commented May 6, 2026

Copy link
Copy Markdown
Member

Replace "const char *typecode;" with "char typecode[3];" to make the arraydescr structure smaller and avoids an indirection.

Replace "const char *typecode;" with "char typecode[3];" to make the
arraydescr structure smaller and avoids an indirection.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32562183 | 📁 Comparing 1b52f8c against main (70e365c)

🔍 Preview build

2 files changed
±library/functions.html
±whatsnew/3.15.html

@vstinner

Copy link
Copy Markdown
MemberAuthor

@scoder@encukou: Would you mind to review this change?

@scoderscoder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Enough to change the struct field back to its previous (padded) size.

@scoder

Copy link
Copy Markdown
Contributor

Personally, I would also have optimised the strcmp() calls into single character comparisons to make it clear to the C compiler that that's almost always enough for taking the decision, but that'd be an optimisation with yet-to-be-measured benefit, not a fix. Definitely not something that comes with a deadline.

@encukou
encukou merged commit 9274d96 into python:mainMay 6, 2026
60 checks passed
@vstinner
vstinner deleted the array_typecode branch May 6, 2026 14:34
@vstinner

Copy link
Copy Markdown
MemberAuthor

Thanks for merging my change @encukou :-)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@vstinner@scoder@encukou