Skip to content

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

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

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

Conversation

@vstinner
Copy link
Copy Markdown
Member

@vstinner vstinner commented May 6, 2026

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
Member Author

vstinner commented May 6, 2026

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

Copy link
Copy Markdown
Contributor

@scoder scoder left a comment

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

scoder commented May 6, 2026

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:main May 6, 2026
60 checks passed
@vstinner vstinner deleted the array_typecode branch May 6, 2026 14:34
@vstinner
Copy link
Copy Markdown
Member Author

vstinner commented May 6, 2026

Thanks for merging my change @encukou :-)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants