Skip to content

gh-131757: allow lru_cache functions to execute concurrently #131758

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 19 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Include/internal/pycore_pyatomic_ft_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
_Py_atomic_store_ullong_relaxed(&value, new_value)
#define FT_ATOMIC_LOAD_ULLONG_RELAXED(value) \
_Py_atomic_load_ullong_relaxed(&value)
#define FT_ATOMIC_ADD_SSIZE(value, new_value) \
_Py_atomic_add_ssize(&value, new_value)

#else
#define FT_ATOMIC_LOAD_PTR(value) value
Expand Down Expand Up @@ -156,6 +158,7 @@
#define FT_ATOMIC_STORE_LLONG_RELAXED(value, new_value) value = new_value
#define FT_ATOMIC_LOAD_ULLONG_RELAXED(value) value
#define FT_ATOMIC_STORE_ULLONG_RELAXED(value, new_value) value = new_value
#define FT_ATOMIC_ADD_SSIZE(value, new_value) (value += new_value) - new_value

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Cross build Linux

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Cross build Linux

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Cross build Linux

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Cross build Linux

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Cross build Linux

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Cross build Linux

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

value computed is not used [-Wunused-value]

Check warning on line 161 in Include/internal/pycore_pyatomic_ft_wrappers.h

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

value computed is not used [-Wunused-value]

#endif

Expand Down
7 changes: 0 additions & 7 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@
return (_functools_state *)state;
}

#ifdef Py_GIL_DISABLED
#define FT_ATOMIC_ADD_SSIZE(value, new_value) \
_Py_atomic_add_ssize(&value, new_value)
#else
#define FT_ATOMIC_ADD_SSIZE(value, new_value) value += new_value
#endif

/* partial object **********************************************************/


Expand Down Expand Up @@ -1180,7 +1173,7 @@
static PyObject *
uncached_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds)
{
PyObject *result;

Check warning on line 1176 in Modules/_functoolsmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'-': result of expression not used [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1176 in Modules/_functoolsmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'-': result of expression not used [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

FT_ATOMIC_ADD_SSIZE(self->misses, 1);
result = PyObject_Call(self->func, args, kwds);
Expand All @@ -1202,7 +1195,7 @@
Py_DECREF(key);
return NULL;
}
int res = _PyDict_GetItemRef_KnownHash((PyDictObject *)self->cache, key, hash, &result);

Check warning on line 1198 in Modules/_functoolsmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'-': result of expression not used [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1198 in Modules/_functoolsmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'-': result of expression not used [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
if (res > 0) {
FT_ATOMIC_ADD_SSIZE(self->hits, 1);
Py_DECREF(key);
Expand All @@ -1210,7 +1203,7 @@
}
if (res < 0) {
Py_DECREF(key);
return NULL;

Check warning on line 1206 in Modules/_functoolsmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'-': result of expression not used [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1206 in Modules/_functoolsmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'-': result of expression not used [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
}
FT_ATOMIC_ADD_SSIZE(self->misses, 1);
result = PyObject_Call(self->func, args, kwds);
Expand Down
Loading