Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

gh-150865: Add PyUnstable_Immortalize - #160138

Open
ZeroIntensity wants to merge 9 commits into
python:mainfrom
ZeroIntensity:c-api/more-immortality
Open

ZeroIntensity wants to merge 9 commits into
python:mainfrom
ZeroIntensity:c-api/more-immortality

Conversation

@ZeroIntensity

@ZeroIntensity ZeroIntensity commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

@read-the-docs-community

read-the-docs-community Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

It's really slow under TSan so it times out.
@prathamhole14

Copy link
Copy Markdown

Hi @ZeroIntensity thank you for the PR.

Immortal types are fixing the free-threaded slowdown for both PRs numpy/numpy/pull/32853 and numpy/numpy/pull/32552 about as well as the tp_free trick.

Benchmarks:

numpy/numpy/pull/32853 types (flagsobj, _array_converter), free-threaded, million calls/s**

Workload Threads static main (mortal) tp_free immortal
a.flags 1 13.9 10.6 9.8 10.3
a.flags 2 27.4 12.4 19.3 19.9
a.flags 4 54.4 9.1 37.8 39.7
a.flags 8 79.1 16.2 54.5 47.3
a.flags.writeable 8 51.5 16.6 37.9 39.5
np.require(a, ['A','W']) 8 4.38 3.78 3.77 4.10
np.broadcast_arrays(a, b) 8 0.60 0.54 0.61 0.61
a.shape (control) 8 64.2 60.5 67.5 63.7

linspace, unique and delete show no difference beyond noise in any build.

numpy/numpy/pull/32552 types (neighborhood iterator, MapIter), free-threaded, million calls/s**

Workload Threads static (main) mortal (your branch now) tp_free (as pushed) immortal
neighborhood iter 1 16.4 14.9 15.2 14.3
neighborhood iter 2 30.2 11.3 30.0 27.6
neighborhood iter 4 59.8 26.8 59.3 55.5
neighborhood iter 8 79.4 35.5 72.2 72.2
a[idx] (MapIter) 8 17.8 17.3 18.3 18.6

GIL build, one thread, ns per call (lower is better)

Workload static mortal tp_free immortal
a.flags 65.7 80.9 87.6 80.2
a.flags.writeable 93.3 105.8 113.6 106.2
neighborhood iter 75.9 76.5 84.1 77.5

import numpy takes the same time in every build (about 58 ms free-threaded, 52 ms GIL).

@ngoldbaum

Copy link
Copy Markdown
Contributor

@ZeroIntensity wasn't there another approach you were thinking about for this?

@ZeroIntensity

Copy link
Copy Markdown
Member Author

Per our discussion during the sprint, I think we reached a consensus that NumPy can use static types for things it would otherwise immortalize, right? As far as I can tell, it should be possible to share third-party static types across interpreters; the only requirement for subinterpreters is to use multi-phase initialization, which doesn't disallow static types. (If you find bugs with that, we should fix those!)

@ngoldbaum

Copy link
Copy Markdown
Contributor

@prathamhole14 @mattip does that work for you two?

@mattip

mattip commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

As far as I know, static types are incompatible with the limited API. If CPython wishes to allow c-extension authors to support subinterpreters, free-threading, and the limited API in a performant way, I think we need to be able to declare heap types immutable and immortal.

@ZeroIntensity

Copy link
Copy Markdown
Member Author

The limited API already has performance problems (all the Py_INCREF calls can't be inlined, for example), which is why you should distribute per-version wheels anyway. Could NumPy use heap types when compiling for the limited API, and then use static types otherwise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review sprint type-feature A feature request or enhancement

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants