ENH: use raw memory allocation APIs under free-threading by kumaraditya303 · Pull Request #30846 · numpy/numpy · GitHub
Skip to content

ENH: use raw memory allocation APIs under free-threading - #30846

Merged
ngoldbaum merged 5 commits into
numpy:mainfrom
kumaraditya303:mimalloc-upstream
Feb 23, 2026
Merged

ngoldbaum merged 5 commits into
numpy:mainfrom
kumaraditya303:mimalloc-upstream

Conversation

@kumaraditya303

Copy link
Copy Markdown
Contributor

Fixes #30494

This PR changes alloc.cpp to use raw memory allocation APIs from CPython so that it can use mimalloc under 3.15 free-threaded builds. I have also removed the unnecessary NPY_BEGIN_THREADS_DEF calls to release the thread state which just adds overhead. For reference CPython also does not releases the thread state when allocating memory so this aligns numpy with CPython.

@kumaraditya303 kumaraditya303 added the 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) label Feb 18, 2026
Comment thread numpy/_core/src/multiarray/alloc.cpp Outdated
Comment thread doc/release/upcoming_changes/30846.compatibility.rst
@ngoldbaum ngoldbaum added this to the 2.5.0 Release milestone Feb 19, 2026

@seberg seberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, since I think Nathan also doesn't think this affects things default Python builds and it is unlikely to affect more than a hand-few of projects, let's get it in.

(I'll apply a tiny change, since I think the release notes section will get mangled up otherwise.)

Comment thread doc/release/upcoming_changes/30846.compatibility.rst Outdated
Comment thread doc/release/upcoming_changes/30846.performance.rst Outdated
@ngoldbaum

Copy link
Copy Markdown
Member

@ngoldbaum
ngoldbaum merged commit 316f598 into numpy:main Feb 23, 2026
84 of 87 checks passed
@kumaraditya303
kumaraditya303 deleted the mimalloc-upstream branch February 25, 2026 06:24
sabasiddique1 pushed a commit to sabasiddique1/numpy that referenced this pull request Mar 4, 2026
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

01 - Enhancement 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Multithreaded scaling bottlenecks on free-threaded Python

3 participants