Skip to content

gh-92914: Round the allocated size for lists up to the even number #92915

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 5 commits into from
May 19, 2022

Conversation

serhiy-storchaka
Copy link
Member

Closes #92914.

@serhiy-storchaka serhiy-storchaka added performance Performance or resource usage needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes labels May 18, 2022
@serhiy-storchaka serhiy-storchaka requested a review from methane May 18, 2022 05:34
@@ -94,6 +94,16 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size)
assert(self->ob_item == NULL);
assert(size > 0);

/* Since the Python memory allocator has granularity of 16 bytes,
Copy link
Member

Choose a reason for hiding this comment

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

alignment is 8bytes on 32bit platform.

cpython/Objects/obmalloc.c

Lines 878 to 884 in b86d783

#if SIZEOF_VOID_P > 4
#define ALIGNMENT 16 /* must be 2^N */
#define ALIGNMENT_SHIFT 4
#else
#define ALIGNMENT 8 /* must be 2^N */
#define ALIGNMENT_SHIFT 3
#endif

So I think we don't need the else { block.

@serhiy-storchaka serhiy-storchaka changed the title gh-92914: Always round up the size allocated for lists up to 16 bytes gh-92914: Round up the allocated size for lists up to the even number May 18, 2022
@serhiy-storchaka serhiy-storchaka changed the title gh-92914: Round up the allocated size for lists up to the even number gh-92914: Round the allocated size for lists up to the even number May 18, 2022
@AlexWaygood AlexWaygood added needs backport to 3.11 only security fixes and removed needs backport to 3.9 only security fixes labels May 18, 2022
@serhiy-storchaka serhiy-storchaka merged commit 8a6af5a into python:main May 19, 2022
@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the list-allocate-round-up branch May 19, 2022 05:44
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label May 19, 2022
@bedevere-bot
Copy link

GH-92941 is a backport of this pull request to the 3.11 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 19, 2022
…ber (pythonGH-92915)

(cherry picked from commit 8a6af5a)

Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label May 19, 2022
@bedevere-bot
Copy link

GH-92942 is a backport of this pull request to the 3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 19, 2022
…ber (pythonGH-92915)

(cherry picked from commit 8a6af5a)

Co-authored-by: Serhiy Storchaka <[email protected]>
ambv pushed a commit that referenced this pull request Jun 7, 2022
miss-islington added a commit that referenced this pull request Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add padding in list allocation
5 participants