8000 gh-126703: Add freelists for small size lists by eendebakpt · Pull Request #129921 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-126703: Add freelists for small size lists #129921

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clear debugging code
  • Loading branch information
eendebakpt committed Mar 4, 2025
commit e9fe6b6ae0882f48dbeba44017bd79ae793941e7
14 changes: 10 additions & 4 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ maybe_small_list_freelist_push(PyObject *self)
Py_ssize_t allocated = op->allocated;
if (allocated < PyList_MAXSAVESIZE) {
return _Py_FREELIST_PUSH(small_lists[allocated], self, Py_small_lists_MAXFREELIST);
//printf("maybe_small_list_freelist_push: allocated %d (mod %d), size %d, id %p\n", (int)allocated, op->allocated, (int)PyList_Size(self), (void *)self);
}
return 0;
}
Expand All @@ -263,13 +262,12 @@ PyList_New(Py_ssize_t size)
if ( size>0) {
memset(op->ob_item, 0, size * sizeof(PyObject *));
}
//printf("obtained list from small_lists[%d] (id %p, op->allocated %d, size %d, PyList_Size %d)\n", (int) size, op, (int)op->allocated, (int)size, (int)PyList_Size( (PyObject*)op));
assert (op->allocated >= size);
}
//op=0;
}
if (op == NULL) {
// do we still need this freelist? if so, we could store it at small_lists[PyList_MAXSAVESIZE-1] with some special casing
// do we still need this freelist? if so, we could store it at small_lists[0] with some special casing
op = _Py_FREELIST_POP(PyListObject, lists);
if (op == NULL) {
op = PyObject_GC_New(PyListObject, &PyList_Type);
Expand Down Expand Up @@ -308,6 +306,15 @@ static PyObject *
list_new_prealloc(Py_ssize_t size)
{
assert(size > 0);
if (size < PyList_MAXSAVESIZE) {
PyListObject *op = (PyListObject *)_Py_FREELIST_POP(PyLongObject, small_lists[size]);
if (op) {
// allocated with ob_item still allocated, but we need to set the other fields
assert (op->allocated >= size);
return op;
}
}

PyListObject *op = (PyListObject *) PyList_New(0);
if (op == NULL) {
return NULL;
Expand Down Expand Up @@ -557,7 +564,6 @@ void small_list_freelist_free(void *obj)

assert(PyList_CheckExact(self));
PyListObject *op = (PyListObject *)self;
//printf("small_list_freelist_free: (op->allocated %d, size %d)\n", (int)op->allocated, (int)PyList_Size(self));
if (op->ob_item != NULL) {
free_list_items(op->ob_item, false);
}
Expand Down
0