BUG: Remove thread-local allocator cache implementation#31237
Conversation
seberg
left a comment
There was a problem hiding this comment.
Thanks for adding benchmarks even. Cool if this just works out for free-threading!
| * CPython uses mimalloc on the free-threaded build, which we trust to cache | ||
| * allocations better than we can. | ||
| */ | ||
| #ifdef Py_GIL_DISABLED |
There was a problem hiding this comment.
Should we maybe just do || PYTHON_USING_MIMALLOC (whatever that exact spelling is)?
There was a problem hiding this comment.
The interpreter only uses mimalloc for the PyMem_Raw on the free-threaded build, so the way I have it spelled here is correct I think.
mhvk
left a comment
There was a problem hiding this comment.
This looks good. Agreed with @seberg that we might as well also not use our home-brew cache generally if a better method is available. Even better if that is linked to a python version -- if so, it will be more obvious when we can just remove the cache altogether.
|
Two approvals so I'm gonna merge this, thanks all! Also thanks @kumaraditya303 for working on this. No shame that we ended up just backing out the two PRs since it led you to making the default allocator mimalloc on the free-threaded build, which benefits all free-threaded applications. |
PR summary
Fixes #31179.
This reverts #30499 and #30673 in favor of the old single global allocator cache on the GIL-enabled build and no cache on the free-threaded build. Since #30499 was merged, CPython has changed
PyMy_RawMallocto use mimalloc instead of the system allocator on the free-threaded build. That means we can rely on mimalloc to cache allocations.The thread-local cache we have currently is complicated and leads to observed races in our CI (#31179).
Using uv's build of Python, I consistently see better allocation performance on the GIL-enabled build:
I see no significant performance change on the free-threaded build.
AI Disclosure
I used Claude to help generate the new benchmark. Happy to leave it out if you don't think it's useful.