Repository navigation
ENH: Convert four self-contained multiarray types to heap types - #32552
prathamhole14 wants to merge 5 commits into
Conversation
5c015b1 to
0954a2a
Compare
0954a2a to
6c23bae
Compare
|
This has conflicts, but overall looks good. Are any of these types involved in hot paths that might affect performance? Although I would think the result would be mixed since the changes will cause rearrangement of memory layout, some will speed things up, some will slow them down. |
0954a2a to
1a1b89b
Compare
|
The per-call overhead is minimal as
|
e6d1c24 to
1a1b89b
Compare
|
LGTM. None of these types are public API, so I think this is clean. Anyone else want to take a look? |
|
Unfortunately I think there's a multithreaded scaling problem that gets introduced here. I used an AI model to generate this code and this benchmark is something of a worse-case scenario. Still, I think it bears thinking about for this work. Put these three files together outside NumPy’s source tree. Use free-threaded Python with the NumPy build you want to test installed, plus a C compiler (Linux/macOS).
|
|
Nathan could there also be free threading issues like this with previous types that were converted to heap types, e.g. in #32502 for example? |
|
I measured the #32502 types on 3.14t. Yes np.require and np.broadcast_arrays are 5-12% slower at 4-8 threads, and linspace and delete show no change. We can fix this directly in Numpy. The bottleneck is In an 8-thread test, this bumped performance from ~40M to 173M objects/s. The only trade-off is a tiny ~3ns overhead on GIL builds. Would you be okay with this? If yes then I will open a follow-up PR for the #32502 types and use the same pattern in this PR. |
|
Nice. That handles the case of the free-threading build mentioned by @ngoldbaum, and also removes the custom |
|
@mattip and @ngoldbaum I updated this PR with the same change as #32853, the four types here no longer define
On a GIL build it costs about 9 ns per iterator, and advanced indexing ( |
|
Lets merge this then and once the CPython PR is merged python/cpython#160138, I will open one new PR that makes all the per-call heap types immortal for both the #32502 types and the #32552 types. I think @seberg is suggesting the same -- #32853 (comment) |
|
I think merging with main will fix the circleci failure. Is there a way forward for you elsewhere without temporarily introducing new free-threaded scaling regressions? |
|
Yes @ngoldbaum
|
PR summary
Related to: #31913, #32451 and #32747
To be merged after #32502
AI Disclosure
Since this is similar to what I did for heap type a PR (#32502), I asked claude opus 5 extra high to make similar changes and corrected at the places where it made wrong decisions. Verified everything myself.