Skip to content
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

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

Merged
merged 5 commits into from May 19, 2022

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented May 18, 2022

Closes #92914.

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

@methane methane May 18, 2022

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
@serhiy-storchaka serhiy-storchaka merged commit 8a6af5a into python:main May 19, 2022
13 checks passed
@miss-islington
Copy link
Contributor

miss-islington commented May 19, 2022

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
@bedevere-bot
Copy link

bedevere-bot commented May 19, 2022

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 <storchaka@gmail.com>
@bedevere-bot
Copy link

bedevere-bot commented May 19, 2022

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 <storchaka@gmail.com>
ambv pushed a commit that referenced this pull request Jun 7, 2022
…H-92915) (GH-92942)

(cherry picked from commit 8a6af5a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington added a commit that referenced this pull request Jun 14, 2022
…H-92915)

(cherry picked from commit 8a6af5a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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