Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2022

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Jan 22, 2022

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

Copy link
Member

@gvanrossum gvanrossum left a comment

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

Copy link
Member

@gvanrossum gvanrossum left a comment

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