Skip to content

bpo-46471: use global singletons for single byte bytes objects#30781

Merged
gvanrossum merged 2 commits into
python:mainfrom
kumaraditya303:deepfreeze
Jan 23, 2022
Merged

bpo-46471: use global singletons for single byte bytes objects#30781
gvanrossum merged 2 commits into
python:mainfrom
kumaraditya303:deepfreeze

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Jan 22, 2022

Copy link
Copy Markdown
Contributor

By using global singletons for single byte bytes objects in deepfreeze, there is no need to generate c code for it so it reduces the size of generated c file and reduces memory use of the objects when they are allocated on the heap as now they are statically allocated and they are already immortal.

https://bugs.python.org/issue46471

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How many of these do you see in deepfreeze.c? Singletons byte literals aren’t that common I guess.

@kumaraditya303

Copy link
Copy Markdown
Contributor Author

How many of these do you see in deepfreeze.c? Singletons byte literals aren’t that common I guess.

cat Python/deepfreeze/deepfreeze.c | grep "(PyObject \*)&_Py_SINGLETON(bytes_characters" | wc -l
200

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I see. co_localspluskinds is a bytes object (flags for args and local vars) and when there's exactly one of those, it qualifies. Clever.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants