-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-111968: Use per-thread slice_cache in free-threading #113972
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,16 +103,20 @@ PyObject _Py_EllipsisObject = _PyObject_HEAD_INIT(&PyEllipsis_Type); | |
|
||
/* Slice object implementation */ | ||
|
||
|
||
void _PySlice_Fini(PyInterpreterState *interp) | ||
void _PySlice_ClearCache(_PyFreeListState *state) | ||
{ | ||
PySliceObject *obj = interp->slice_cache; | ||
PySliceObject *obj = state->slice_state.slice_cache; | ||
if (obj != NULL) { | ||
interp->slice_cache = NULL; | ||
state->slice_state.slice_cache = NULL; | ||
PyObject_GC_Del(obj); | ||
} | ||
} | ||
|
||
void _PySlice_Fini(_PyFreeListState *state) | ||
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. This is identical to 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. Let's keep both names; I don't want to confuse people who work on the default build. |
||
{ | ||
_PySlice_ClearCache(state); | ||
} | ||
|
||
/* start, stop, and step are python objects with None indicating no | ||
index is present. | ||
*/ | ||
|
@@ -122,11 +126,11 @@ _PyBuildSlice_Consume2(PyObject *start, PyObject *stop, PyObject *step) | |
{ | ||
assert(start != NULL && stop != NULL && step != NULL); | ||
|
||
PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
_PyFreeListState *state = _PyFreeListState_GET(); | ||
PySliceObject *obj; | ||
if (interp->slice_cache != NULL) { | ||
obj = interp->slice_cache; | ||
interp->slice_cache = NULL; | ||
if (state->slice_state.slice_cache != NULL) { | ||
obj = state->slice_state.slice_cache; | ||
state->slice_state.slice_cache = NULL; | ||
_Py_NewReference((PyObject *)obj); | ||
} | ||
else { | ||
|
@@ -354,13 +358,13 @@ Create a slice object. This is used for extended slicing (e.g. a[0:10:2])."); | |
static void | ||
slice_dealloc(PySliceObject *r) | ||
{ | ||
PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
_PyFreeListState *state = _PyFreeListState_GET(); | ||
_PyObject_GC_UNTRACK(r); | ||
Py_DECREF(r->step); | ||
Py_DECREF(r->start); | ||
Py_DECREF(r->stop); | ||
if (interp->slice_cache == NULL) { | ||
interp->slice_cache = r; | ||
if (state->slice_state.slice_cache == NULL) { | ||
state->slice_state.slice_cache = r; | ||
} | ||
else { | ||
PyObject_GC_Del(r); | ||
|
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.
@erlend-aasland @colesbury
IMO, we should rename _PyFreeListState if we consider slice_cache is not freelist :)
Do you have any good suggestion?
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.
It's basically a freelist of max-length 1 🤷
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.
In that case, let's maintain the current naming. (Changing is quite stressful)