Skip to content

gh-126868: Add freelist for compact int objects #126865

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 25 commits into from
Dec 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0713034
Add freelist of compact int objects
eendebakpt Nov 15, 2024
be58ade
fix build
eendebakpt Nov 15, 2024
3f50b54
cleanup freelist at exit
eendebakpt Nov 15, 2024
fa97302
fix memory leak; align with float implementation
eendebakpt Nov 16, 2024
d72486f
remove stale comment
eendebakpt Nov 16, 2024
e07c218
remove unused function
eendebakpt Nov 16, 2024
328e0c1
avoid some problematic decrefs
eendebakpt Nov 16, 2024
e1dc2b3
jit build
eendebakpt Nov 16, 2024
9df776b
📜🤖 Added by blurb_it.
blurb-it[bot] Nov 16, 2024
6b73046
Merge branch 'main' into int_freelist
eendebakpt Nov 16, 2024
db8247e
Apply review suggestions
Fidget-Spinner Nov 20, 2024
d1e4aa2
Fixup
Fidget-Spinner Nov 20, 2024
644e85a
review comments part 1
eendebakpt Nov 21, 2024
9f86b6e
review comments part 2
eendebakpt Nov 21, 2024
88274d6
Merge branch 'main' into int_freelist
eendebakpt Nov 21, 2024
1e548bd
review suggestion
eendebakpt Nov 23, 2024
13bc3e9
Merge branch 'main' into int_freelist
eendebakpt Dec 2, 2024
60220c0
add small int check to _PyLong_ExactDealloc
eendebakpt Dec 2, 2024
593d621
add COMPARE_OP_INT
eendebakpt Dec 2, 2024
efde111
review comment
eendebakpt Dec 7, 2024
928e912
Merge branch 'main' into int_freelist
eendebakpt Dec 7, 2024
437c24c
regenerate
eendebakpt Dec 7, 2024
b034948
Update Misc/NEWS.d/next/Core_and_Builtins/2024-11-16-22-37-46.gh-issu…
eendebakpt Dec 7, 2024
19f64f6
Merge branch 'main' into int_freelist
eendebakpt Dec 12, 2024
14681c1
Merge branch 'main' into int_freelist
eendebakpt Dec 12, 2024
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
Fixup
  • Loading branch information
Fidget-Spinner committed Nov 20, 2024
commit d1e4aa268ed83dfcb35b18b040451a75bd003bee
18 changes: 12 additions & 6 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3620,13 +3620,11 @@ long_richcompare(PyObject *self, PyObject *other, int op)
void
_PyLong_ExactDealloc(PyObject *self)
{
if (PyLong_CheckExact(self)) {
if (_PyLong_IsCompact((PyLongObject *)self)) {
_Py_FREELIST_FREE(ints, self, PyObject_Free);
return;
}
if (_PyLong_IsCompact((PyLongObject *)self)) {
_Py_FREELIST_FREE(ints, self, PyObject_Free);
Copy link
Member

Choose a reason for hiding this comment

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

I just realised that we didnt check for if it's a smallint cached value here. It should be rejected there

Copy link
Member

@Fidget-Spinner Fidget-Spinner Nov 21, 2024

Choose a reason for hiding this comment

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

Nevermind. It's not needed because (theoretically) the refcount of a smallint never hits 0 due to it being immortal, so this code will never be called on it. Can you add an assert to be safe?

Copy link
Member

Choose a reason for hiding this comment

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

This also means my comment about the small ints was wrong. Could you remove that please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment has been adapted. If the refcount can never become zero, then the code in long_dealloc checking for small ints can be removed (perhaps also with an assert). Since this is something unrelated to the freelists I will make a separate PR for that and rebase this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Fidget-Spinner I think your first remark was right after all and we do need to check for smallints (at least in the 32-bit stable ABI build). I will add the check once there is consensus on #127120 (which might very well be the status quo)

return;
}
Py_TYPE(self)->tp_free(self);
PyObject_Free(self);
}

static void
Expand All @@ -3650,6 +3648,14 @@ long_dealloc(PyObject *self)
}
}
}

if (PyLong_CheckExact(self)) {
if (_PyLong_IsCompact((PyLongObject *)self)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Fidget-Spinner The _PyLong_IsCompact check has already been done in this method, can we move this into the if (pylong && _PyLong_IsCompact(pylong)) part?

Also, can we remove the pylong && part? I think pylong can never be NULL. (PyLong_CheckExact assumes the pointer is not NULL I think)

Copy link
Member

Choose a reason for hiding this comment

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

Ok that sounds good

_Py_FREELIST_FREE(ints, self, PyObject_Free);
return;
}
}

Py_TYPE(self)->tp_free(self);
}

Expand Down
Loading