-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
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
Changes from 1 commit
0713034
be58ade
3f50b54
fa97302
d72486f
e07c218
328e0c1
e1dc2b3
9df776b
6b73046
db8247e
d1e4aa2
644e85a
9f86b6e
88274d6
1e548bd
13bc3e9
60220c0
593d621
efde111
928e912
437c24c
b034948
19f64f6
14681c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
return; | ||
} | ||
Py_TYPE(self)->tp_free(self); | ||
PyObject_Free(self); | ||
} | ||
|
||
static void | ||
|
@@ -3650,6 +3648,14 @@ long_dealloc(PyObject *self) | |
} | ||
} | ||
} | ||
|
||
if (PyLong_CheckExact(self)) { | ||
if (_PyLong_IsCompact((PyLongObject *)self)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Fidget-Spinner The Also, can we remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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)