8000 MNT: disable the allocator cache for nogil builds by ngoldbaum · Pull Request #26251 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MNT: disable the allocator cache for nogil builds #26251

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 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
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
MNT: disable the allocator cache for nogil builds
  • Loading branch information
ngoldbaum committed Apr 9, 2024
commit 04a6fe2f9d032f76273871c130f3fc4b51c1e8f5
4 changes: 4 additions & 0 deletions numpy/_core/src/multiarray/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ _npy_alloc_cache(npy_uintp nelem, npy_uintp esz, npy_uint msz,
assert((esz == 1 && cache == datacache) ||
(esz == sizeof(npy_intp) && cache == dimcache));
assert(PyGILState_Check());
#ifndef Py_GIL_DISABLED
if (nelem < msz) {
if (cache[nelem].available > 0) {
return cache[nelem].ptrs[--(cache[nelem].available)];
}
}
#endif
p = alloc(nelem * esz);
if (p) {
#ifdef _PyPyGC_AddMemoryPressure
Expand Down Expand Up @@ -131,12 +133,14 @@ _npy_free_cache(void * p, npy_uintp nelem, npy_uint msz,
cache_bucket * cache, void (*dealloc)(void *))
{
assert(PyGILState_Check());
#ifndef Py_GIL_DISABLED
if (p != NULL && nelem < msz) {
if (cache[nelem].available < NCACHE) {
cache[nelem].ptrs[cache[nelem].available++] = p;
return;
}
}
#endif
dealloc(p);
}

Expand Down
0