8000 Draft: gh-127119: Faster check for small ints in long_dealloc (debug) by eendebakpt · Pull Request #128187 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Draft: gh-127119: Faster check for small ints in long_dealloc (debug) #128187

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

Closed
wants to merge 40 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
cfb70cb
Faster check for small ints in long_dealloc
eendebakpt Dec 4, 2024
426dd09
📜🤖 Added by blurb_it.
blurb-it[bot] Dec 4, 2024
4639642
Use int immortality bit for small int check
eendebakpt Dec 5, 2024
d9c26d3
Merge branch 'small_int_immortal_v2' of github.com:eendebakpt/cpython…
eendebakpt Dec 5, 2024
2f73d47
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 5, 2024
3b6e1fe
fix compiler warnings
eendebakpt Dec 5, 2024
03184a7
Merge branch 'small_int_immortal_v2' of github.com:eendebakpt/cpython…
eendebakpt Dec 5, 2024
5eca812
compiler warnings
eendebakpt Dec 5, 2024
fedc102
some documentation updates
eendebakpt Dec 5, 2024
c733d25
Update Objects/longobject.c
eendebakpt Dec 5, 2024
829a595
Merge branch 'small_int_immortal_v2' of github.com:eendebakpt/cpython…
eendebakpt Dec 5, 2024
39da0ea
Update Tools/gdb/libpython.py
eendebakpt Dec 5, 2024
5058e53
tests!
eendebakpt Dec 5, 2024
8a3d00f
tests!
eendebakpt Dec 5, 2024
878207a
update _PyLong_IsNonNegativeCompact
eendebakpt Dec 5, 2024
068a16a
Apply suggestions from code review
eendebakpt Dec 11, 2024
a65ec5a
review comments
eendebakpt Dec 11, 2024
38fe25f
Merge branch 'small_int_immortal_v2' of github.com:eendebakpt/cpython…
eendebakpt Dec 11, 2024
32b6e44
spacing
eendebakpt Dec 11, 2024
8543c78
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 11, 2024
e232ca4
Update Tools/gdb/libpython.py
eendebakpt Dec 11, 2024
f1ce753
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 13, 2024
99a2fc7
whitespace
eendebakpt Dec 13, 2024
f6a76b0
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 17, 2024
9894866
Apply suggestions from code review
eendebakpt Dec 17, 2024
7834406
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 18, 2024
d91b6e3
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 20, 2024
ebc7e17
Update Modules/_testcapi/immortal.c
eendebakpt Dec 22, 2024
aaf110b
Update Modules/_testcapi/immortal.c
eendebakpt Dec 22, 2024
8fcc1d0
Update Include/cpython/longintrepr.h
eendebakpt Dec 22, 2024
aff8812
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 22, 2024
ebb0bca
review comments
eendebakpt Dec 22, 2024
8d8e794
include pycore_long.h
eendebakpt Dec 22, 2024
4a07ba1
header
eendebakpt Dec 22, 2024
1d5b2e0
include pycore_long.h
eendebakpt Dec 22, 2024
cfb9120
debug build failure
eendebakpt Dec 22, 2024
b606c09
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 23, 2024
b4c8444
fix bug when copying the immortal bit
eendebakpt Dec 23, 2024
3a553d1
test small int test
eendebakpt Dec 23, 2024
62939d1
print
eendebakpt Dec 23, 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
Next Next commit
Faster check for small ints in long_dealloc
  • Loading branch information
eendebakpt committed Dec 4, 2024
commit cfb70cb2fdb02457c02b7ffb3792da78d2292ba4
32 changes: 18 additions & 14 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3611,24 +3611,28 @@ long_richcompare(PyObject *self, PyObject *other, int op)
Py_RETURN_RICHCOMPARE(result, 0, op);
}

static inline int
/// Return 1 if the object is one of the immortal small ints
_long_is_small_int(PyObject *op)
{
return (((PyObject *)(&_PyLong_SMALL_INTS[0]) <= op)
&& (op <= (PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS +_PY_NSMALLPOSINTS]));
}
static void
long_dealloc(PyObject *self)
{
/* This should never get called, but we also don't want to SEGV if
* we accidentally decref small Ints out of existence. Instead,
* since small Ints are immortal, re-set the reference count.
*/
PyLongObject *pylong = (PyLongObject*)self;
if (pylong && _PyLong_IsCompact(pylong)) {
stwodigits ival = medium_value(pylong);
if (IS_SMALL_INT(ival)) {
PyLongObject *small_pylong = (PyLongObject *)get_small_int((sdigit)ival);
if (pylong == small_pylong) {
_Py_SetImmortal(self);
return;
}
}
#ifndef Py_GIL_DISABLED
if (_long_is_small_int(self)) {
/* This should never get called, but we also don't want to SEGV if
* we accidentally decref small Ints out of existence. Instead,
* since small Ints are immortal, re-set the reference count.
*
* See PEP 683, section Accidental De-Immortalizing for details
*/
_Py_SetImmortal(self);
return;
}
#endif
Py_TYPE(self)->tp_free(self);
}

Expand Down
Loading
0